JSP Tutorials - Herong's Tutorial Examples - v5.11, by Herong Yang
Archived: Using JavaBean without Import Element Error
This section describes the compilation error on a JSP page that uses a JavaBean without the 'page import' directive element to import the JavaBean class declared without package name.
So what can we do about the compilation error presented in the previous section? Can we remove the import statement? The answer is no. You can try by running the following modified JSP page, FirstBeanModified.jspx:
<?xml version="1.0"?> <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2"> <!-- FirstBeanModified.jsp - Copyright (c) 2006 HerongYang.com. All Rights Reserved. --> <html><body> <jsp:useBean id="b" class="FirstBean"/> <jsp:setProperty name="b" property="text" value="Hello world!"/> Property from my Bean: <jsp:getProperty name="b" property="text"/> <br/> Info from my Bean: <jsp:expression>b.getInfo()</jsp:expression> </body></html> </jsp:root>
You will get the following compilation error saying FirstBean is not resolvable:
org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: 7 in the jsp file: /jsp/FirstBeanModified.jspx Generated servlet error: [javac] Compiling 1 source file D:\local\jakarta-tomcat-4.1.18\work\Standalone\localhost \_\jsp\FirstBeanModified_jsp.java:43: cannot resolve symbol symbol : class FirstBean location: class org.apache.jsp.FirstBeanModified_jspx FirstBean b = null; ^
The actual cause of this error is not the compiler. It is the Tomcat compilation environment. Because you can compile the converted class, FirstBeanModified_jspx.java, correctly in a command window with same class paths used by the Tomcat environment.
The only option left to use a JavaBean with Tomcat 4.1.18 and JDK 1.4.1 is to create your JavaBean in a named package. The next tutorial will give you an example.
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
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
Developing Web Applications with Servlet
Archived: Installing GlassFish JSTL 1.2 on Tomcat
Archived: Downloading and Installing Tomcat 7
Archived: Installing Tomcat 5.5.7
Archived: Installing Tomcat 4.1.18
Archived: Java Class Converted by Tomcat 4.1.18
Archived: Hijacking Servlet Converted from JSP
Archived: Using Perl LWP::Debug Module to Debug
Archived: Installing JSTL 1.0 Apache Implementation
Archived: Upgrade JDK 1.3 to JDK 1.4 on Tomcat 4.1
Archived: Compilation Errors with JDK 1.4