JSP Tutorials - Herong's Tutorial Examples - v5.11, by Herong Yang
"jsp:useBean" Requires Fully Qualified Class Name
This section provides a tutorial example showing the JSP error, if the short class name instead of the fully qualified class name is used in the 'jsp:useBean' action element.
While testing JavaBeen, I noticed an error with Tomcat 9. It relates to the "class" attribute in the "useBean" JSP element.
Here is an example JSP page that uses the class name, not the fully qualified class name, in the "useBean" JSP element:
<?xml version="1.0"?> <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"> <!-- UseBeanClassError.jsp - Copyright (c) 2006 HerongYang.com. All Rights Reserved. --> <jsp:directive.page contentType="text/html"/> <html><body> <jsp:directive.page import="herong.CacheBean"/> <jsp:useBean id="b" class="CacheBean"/> <jsp:setProperty name="b" property="text" value="Hello world!"/> Property from my JavaBean: <jsp:getProperty name="b" property="text"/> <br/> Info from my JavaBean: <jsp:expression>b.getInfo()</jsp:expression> </body></html> </jsp:root>
Deploy this JSP page to the Tomcat 9 server and view it in a Web browser. You will get this error:
HTTP Status 500 – Internal Server Error Type Exception Report Message /UseBeanClassError.jspx (line: [9], column: [40]) The value for the useBean class attribute [CacheBean] is invalid. Description The server encountered an unexpected condition that prevented it from fulfilling the request. Exception org.apache.jasper.JasperException: /UseBeanClassError.jspx (line: [9], column: [40]) The value for the useBean class attribute [CacheBean] is invalid. org.apache.jasper.compiler.DefaultErrorHandler.jspError(...) org.apache.jasper.compiler.ErrorDispatcher.dispatch(...) ... org.apache.jasper.compiler.Generator.generate(Generator.java:3667) org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:257) org.apache.jasper.compiler.Compiler.compile(Compiler.java:385) org.apache.jasper.compiler.Compiler.compile(Compiler.java:362) org.apache.jasper.compiler.Compiler.compile(Compiler.java:346) org.apache.jasper.JspCompilationContext.compile(...) org.apache.jasper.servlet.JspServletWrapper.service(...) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) Apache Tomcat/9.0.12
The error message is not that clear. But I know the issue is caused by the "class" attribute in the "useBean" element. You must provide the fully qualified class name like herong.CacheBean, not the short class name.
The above JSP page was working fine with Tomcat 7, which uses an older cookie standard.
Table of Contents
JSP (JavaServer Pages) Overview
Tomcat Installation on Windows Systems
Syntax of JSP Pages and JSP Documents
►JavaBean Objects and "useBean" Action Elements
►"jsp:useBean" Requires Fully Qualified Class Name
Servlet Class Converted from UseBean.jspx
Setting and Getting JavaBean's Properties
Using JavaBean Objects in Scripting Elements
Using Java Objects as JavaBeans
getProperty() Error on Tomcat 7
Refreshing Loaded JavaBean Classes
Importing Unnamed Package Class Error
Using JavaBean without Import Element Error
Creating JavaBean Classes in Named Packages
"NoClassDefFoundError" Exception
Managing HTTP Response Header Lines
Non-ASCII Characters Support in JSP Pages
Overview of JSTL (JSP Standard Tag Libraries)
Multiple Tags Working Together
Using Tomcat on CentOS Systems
Connecting to SQL Server from Servlet