JSP and JSTL Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 3.09, 2006

Tomcat 5.5.7

JSP/JSTL Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

Using Cookies

Using JavaBean Classes

HTTP Response Header Lines

Non ASCII Characters

JSTL and Expression Language

File Upload

Execution Context

JSP Elements

JSP Standard Tag Libraries (JSTL)

JSP Custom Tag

... Table of Contents

Installing Tomcat 5.5.7

Tomcat 5.5.7 is a Web server and supports Servlet 2.4 and JSP 2.0. It requires JDK 1.5 or later. I did the following to get Tomcat 5.5.7 installed:

1. Checked JDK requirement. I had JDK 1.5.0 installed on \local\j2sdk1.5.0.

2. Downloaded jakarta-tomcat-5.5.7.zip from http://jakarta.apache.org/tomcat.

3. Unziped jakarta-tomcat-5.5.7.zip in \local.

4. Started Tomcat server:

cd \local\jakarta-tomcat-5.5.7\bin
set JAVA_HOME=\local\j2sdk1.5.0
startup

5. Tomcat created a separate command window, on which I got:

(Date) 11:09:23 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
(Date) 11:09:23 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 631 ms
(Date) 11:09:23 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
(Date) 11:09:23 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.7
......

6. Ran Internet Explorer (IE) with url: http://localhost:8080. I got the Tomcat home page with the following message on it:

Apache Tomcat/5.5.7 If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!

Using Tomcat as a Web Server

To find out where it document root directory of this Web server, let's create hello.html:

<html><body>Hello world!</body></html>

Then save hello.html to \local\jakarta-tomcat-5.5.7\webapps\ROOT. Now, run IE with url: http://localhost:8080/hello.html. You should see "Hello world!" in the IE window.

Now, we know that the Web server:

Listening on port: 8080
Serving document from: \local\jakarta-tomcat-5.5.7\webapps\ROOT

To change the port number, you need to edit \local\jakarta-tomcat-5.5.7\conf\server.xml.

'Hello world!' Example in JSP

To verify if Tomcat supports JSP or not, let's create hello.jsp:

<html><body>
<% out.println("Hello world!"); %>
</body></html>

Then save hello.jsp to \local\jakarta-tomcat-5.5.7\webapps\ROOT. Now, ran IE with url: http://localhost:8080/hello.jsp. You should see "Hello world!" in the IE window.

Congratulations! I have successfully served an JSP page through Tomcat.

Using JavaBean Classes

To test JavaBean on Tomcat 5.5.7, I used the TempratureConvertor.jsp and TempratureConvertorBean.java created earlier in this book. First I copied TempratureConvertor.jsp to \local\jakarta-tomcat-5.5.7\webapps\ROOT.

Then I started IE with http://localhost:8080/TempratureConvertor.jsp. I got the following error in IE:

......
org.apache.jasper.JasperException: 
   /jsp/TempratureConvertor.jsp(8,61) The value for the useBean class
   attribute herong.TempratureConvertorBean is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErr...
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatche...
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatche...
......

Of course, we have a problem here. The JavaBean used by this page has not been installed on Tomcat yet. But this error message is not very clear. To fix the problem, I compiled TempratureConvertorBean.java and copied the class file to \local\jakarta-tomcat-5.5.7\webapps\root\web-inf\classes\herong. After that, my JSP page worked correctly:

My TempraturConvertorBean - Version 1.00
Setting property "fahrenheit" to 70.0.
Getting property "celsius" back: 21.11111111111111
Dr. Herong Yang, updated in 2006
JSP and JSTL Tutorials - Herong's Tutorial Notes - Tomcat 5.5.7