Tomcat Setup and Configuration for CS320

This document describes a step-by-step procedure to install a Tomcat server with additional packages under Windows 2000.

[Preparation]

Before installing Tomcat, make sure you already have J2SE 1.4 or above installed. If not, download J2SE 1.5.0 and install it first. In the rest of the document, I will assume that J2SE is installed under the directory d:\j2sdk.

[Download and Installation]

Download Tomcat 5.5.9 binary release from the Apache Jakarta Project, and unzip the files to a local directory, e.g. d:\jakarta-tomcat-5.5.9.

Note that there are several Tomcat versions available for download. Version 5.5.9 is the current stable version that supports the latest Servlet and JSP specifications, and is the version that we are going to use in the class. Also note that for installation on Windows, you may choose to download either a ZIP file or an EXE file. If you want to setup Tomcat as a service on Windows 2000/XP, you should download the EXE file; otherwise you should download the ZIP file because a) installation from the ZIP file does not require administrator privilege, and b) in a development environment, you may often want to restart your Tomcat server, and it is easier to start up, shut down, and restart the server as a regular process than as a service.

[Environment Variables]

Set the JAVA_HOME environment variable to the directory where J2SE is installed, e.g d:\j2sdk. To check whether these environment variables are set properly, open a Command Prompt and do:
> echo %JAVA_HOME%
[Understand Tomcat Directory Structure]

Some key Tomcat directories, all relative to the directory where it is installed (and I'll later refer to this directory as %CATALINA_HOME%) are the following:
[1st Test Run]

Start Tomcat server by running the startup.bat script. Open a browser window and go to URL http://localhost:8080, and the "Congratulation" page should appear.

Shutdown Tomcat server by running the shutdown.bat script.

[Edit Configuration Files]

Open web.xml and search for "invoker". Uncomment the <servlet> and <servlet-mapping> elements for the invoker servlet.

Open tomcat-users.xml, and add a manager user, e.g.
  <user name="cysun" manager="abcd" roles="manager" />
The user names and passwords are arbitary.

[Context]

Download context.xml  to the %CATALINA_HOME%\conf\Catalina\localhost directory. Rename the file to the login name assigned to you on the CS server, e.g. cs320stu31.xml, and edit the file to replace "username" with the your actual login name on the CS server. Again, assume your login name is cs320stu31, your cs320stu31.xml should look like the following:
<Context
    path="/cs320stu31"
    docBase="cs320stu31"
    reloadable="true"
    useNaming="true">
</Context>
A context file describes the URL path, the file location, and the runtime environments for a web application. In particular,
[Understand Web Application Directory Structure]

Like the Tomcat server itself, each web application has its own directory structure, rooted at docBase specified in the context file. Assume your docBase is set to cs320stu31 as described in the last section, you need to create the following subdirectories under %CATALINA_HOME%\webapps:
[Additonal Libraries]

Download the MySQL JDBC Driver, MySQL Connector/J 3.1  from www.mysql.com, and extract mysql-connector-java-3.1.10-bin.jar to %CATALINA_HOME%\common\lib.

Download JSP Standard Tag Library (JSTL) from the Apache Jarkata Project. There are many taglibs available, and the one you should get is jarkata-taglibs-standard-1.1.2.zip. Once you download the file, extract jstl.jar and standard.jar to %CATALINA_HOME%\common\lib.

[2nd Test Run]

Download HelloJSTL.jsp to your docBase directory, and use a browser to access it at http://localhost:8080/username/HelloJSTL.jsp, and you should see the message "Hello World in JSTL". Download HelloServlet.class to your docBase/WEB-INF/classes directory, access it with the URL http://localhost:8080/username/servlet/HelloServlet, and your should see a message "Servlet invoked!" and the display of current time.

[FAQ]

Q: I followed all the instructions but when I tried to access HelloJSTL.jsp, I got the error message "org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application".

A: go to the common\lib folder under your tomcat folder and see whether standard.jar and jstl.jar are there. Sometimes WinZip will create a subfolder under common\lib (e.g. jarkata-taglibs-standard-1.1.2). If so, find the two jar files in that subfolder and move them to common\lib.

Q: I can access the JSP pages without any problem, however, when I tried to access the servlet through the url http://localhost:8080/username/HelloServlet, I got the HTTP Status 404 error.

A: To access the servlet, the url should be something  like http://localhost:8080/username/servlet/HelloServlet. Note that there's an extra servlet/ between the servlet name and the docBase path. The reason for this is the configuration in web.xml under the /conf directory. Check out the <servlet-mapping> element of the "invoker" servlet and you'll see why.

THE END (or the beginning of a fun class)