getProperty() Error on Tomcat 7

This section provides a tutorial example on how Tomcat 7 refuses to convert 'getProperty' elements if the JavaBean is not initiated by a 'useBean' element.

While testing JavaBean on Tomcat 7 and Tomcat 9, I noticed something strange. Below is an example JSP document that worked ok on Tomcat 5.

<?xml version="1.0"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1">
<!-- GetPropertyError.jspx
 - Copyright (c) 2006 HerongYang.com. All Rights Reserved.
-->
<jsp:directive.page contentType="text/html"/>
<html><body>
<jsp:scriptlet><![CDATA[
   herong.DemoBean b = new herong.DemoBean();
   pageContext.setAttribute("b", b, PageContext.PAGE_SCOPE);
]]></jsp:scriptlet>

<jsp:setProperty name="b" property="author" value="Unknown"/>
Line 31: author =
<jsp:getProperty name="b" property="author"/><br/>

</body></html>
</jsp:root>

Now try it on Tomcat 7, you will the following error:

HTTP Status 500 - file:/GetPropertyError.jspx() jsp:getProperty
for bean with name 'b'. Name was not previously introduced as per JSP.5.3

type: Exception report

message: file:/GetPropertyError.jspx() jsp:getProperty for bean
with name 'b'. Name was not previously introduced as per JSP.5.3

description: The server encountered an internal error that prevented
it from fulfilling this request.

exception:
org.apache.jasper.JasperException: file:/GetPropertyError.jspx()
jsp:getProperty for bean with name 'b'. Name was not previously
introduced as per JSP.5.3

org.apache.jasper.compiler.Generator$GenerateVisitor.visit()
org.apache.jasper.compiler.Node$GetProperty.accept()
org.apache.jasper.compiler.Node$Nodes.visit()
org.apache.jasper.compiler.Node$Visitor.visitBody()
org.apache.jasper.compiler.Generator$GenerateVisitor.visit()
org.apache.jasper.compiler.Node$UninterpretedTag.accept()
org.apache.jasper.compiler.Node$Nodes.visit()
org.apache.jasper.compiler.Node$Visitor.visitBody()
org.apache.jasper.compiler.Generator$GenerateVisitor.visit()
org.apache.jasper.compiler.Node$UninterpretedTag.accept()
org.apache.jasper.compiler.Node$Nodes.visit()
org.apache.jasper.compiler.Node$Visitor.visitBody()
org.apache.jasper.compiler.Node$Visitor.visit()
org.apache.jasper.compiler.Node$JspRoot.accept()
org.apache.jasper.compiler.Node$Nodes.visit()
org.apache.jasper.compiler.Node$Visitor.visitBody()
org.apache.jasper.compiler.Node$Visitor.visit()
org.apache.jasper.compiler.Node$Root.accept()
org.apache.jasper.compiler.Node$Nodes.visit()
org.apache.jasper.compiler.Generator.generate()
org.apache.jasper.compiler.Compiler.generateJava()
org.apache.jasper.compiler.Compiler.compile()
org.apache.jasper.compiler.Compiler.compile()
org.apache.jasper.compiler.Compiler.compile()
org.apache.jasper.JspCompilationContext.compile()
org.apache.jasper.servlet.JspServletWrapper.service()
org.apache.jasper.servlet.JspServlet.serviceJspFile()
org.apache.jasper.servlet.JspServlet.service()
javax.servlet.http.HttpServlet.service()

note The full stack trace of the root cause is available in the Apache
Tomcat/7.0.32 logs.

Apache Tomcat/7.0.32

It is very strange to me that Tomcat 7 refuses to convert (getProperty name="b"...) and saying that "Name was not previously introduced as per JSP.5.3". But it accepts (setProperty name="b"...) without any problem.

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

 References

 Full Version in PDF/EPUB