"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"/>
<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"/>
Info from my JavaBean:

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.

org.apache.jasper.JasperException: /UseBeanClassError.jspx
 (line: [9], column: [40]) The value for the useBean class attribute
 [CacheBean] is invalid.

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

 About This Book

 JSP (JavaServer Pages) Overview

 Tomcat Installation on Windows Systems

 JSP Scripting Elements

 Java Servlet Introduction

 JSP Implicit Objects

 Syntax of JSP Pages and JSP Documents

 JSP Application Session

 Managing Cookies in JSP Pages

JavaBean Objects and "useBean" Action Elements

 What Is a JavaBean

 "jsp: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

 Performance of JSP Pages

 EL (Expression Language)

 Overview of JSTL (JSP Standard Tag Libraries)

 JSTL Core Library

 JSP Custom Tags

 JSP Java Tag Interface

 Custom Tag Attributes

 Multiple Tags Working Together

 File Upload Test Application

 Using Tomcat on CentOS Systems

 Using Tomcat on macOS Systems

 Connecting to SQL Server from Servlet

 Developing Web Applications with Servlet

 Archived Tutorials


 Full Version in PDF/EPUB