|
Tomcat 4.1.18 with JDK 1.4.1
Part:
1
2
This chapter explains:
- How to change Tomcat 4.1.18 installation from using JDK 1.3.1 to using JDK 1.4.1.
- Compilation issues of using JavaBean classes in unnamed packages.
- How to create JavaBean classes in named packages.
Upgrading Tomcat 4.1.18 to JDK 1.4.1
One of the readers reported a JSP compilation issue while following my tutorials
with Tomcat 4.1.29 and JDK 1.4.x. In order to understand the issue better, I upgraded
my Tomcat 4.1.18 installation from JDK 1.3.1 to JDK 1.4.1:
1. Checked my JDK 1.4.1 installation. The following command shows that I have JDK 1.4.1_01
working correctly:
>\local\j2sdk1.4.1\bin\java -version
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
2. Started Tomcat server with JDK 1.4.1 without any problem:
cd \local\jakarta-tomcat-4.1.18\bin
set JAVA_HOME=\local\j2sdk1.4.1
startup
3. Created the following JSP page, hello.jsp, and copied to \local\jakarta-tomcat-4.1.18\webapps\ROOT:
<html><body>
<% out.println("Hello world!"); %>
</body></html>
4. Ran Internet Explorer (IE) with url: http://localhost:8080/hello.jsp.
You should see "Hello world!" in the IE window.
I am pretty sure now my Tomcat server is running ok with JDK 1.4.1.
Compilation Errors with Tomcat 4.1.18 and JDK 1.4.1
To demonstrate the compilation error, run IE on the following JSP page I created in the
"Using JavaBean Classes" chapter, UseBean.jsp
<?xml version="1.0"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2">
<!-- UseBean.jsp
Copyright (c) 2002 by Dr. Herong Yang
-->
<html><body>
<jsp:directive.page import="CacheBean"/>
<jsp:useBean id="b" class="CacheBean"/>
<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 see a compilation error in the IE window:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 8 in the jsp file: /UseBean.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\local\jakarta-tomcat-4.1.18\work\Standalone\localhost
\_\UseBean_jsp.java:7: '.' expected
import CacheBean;
This tells us that JDK 1.4.1 does not allow import statement to be used on classes
in unnamed packages. So what can we do about this? Can we remove the import statement?
The answer is no. You can try by running the following modified JSP page, UseBeanModified.jsp:
<?xml version="1.0"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2">
<!-- UseBeanModified.jsp
Copyright (c) 2002 by Dr. Herong Yang
-->
<html><body>
<jsp:useBean id="b" class="CacheBean"/>
<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>
(Continued on next part...)
Part:
1
2
|