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/XP.

[Preparation]

Before installing Tomcat, make sure you already have J2SE 1.5 or above installed. If not, download the latest JDK and install it first.

[Download and Installation]

Download Tomcat 6.0.14 binary release from the Apache Project (just the "Core" package), and unzip the files to a local directory, e.g. d:\apache-tomcat-6.0.14.

Note that there are several Tomcat versions available for download. Version 6.0.14 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 installation from the ZIP file does not require administrator privilege.

[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.

[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:
[Additional Libraries]

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

Download JSP Standard Tag Library (JSTL) from the Apache Jarkata Project, and extract jstl.jar and standard.jar to %CATALINA_HOME%\lib.

[2nd Test Run]

Download web.xml to your docBase/WEB-INF directory.

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/HelloServlet, and your should see a message "Servlet invoked!" and the display of current time.

[FAQ]

Q: How do I set the JAVA_HOME environment variable on Windows 2000/XP?

A: Right click on My Computer and select Properties -> Advanced -> Environment Variable. Check whether JAVA_HOME is already defined, and if not, click on New to add it to either User Variables or Systems Variables (create new System Variables will require administrator privilege). The variable name is JAVA_HOME, and the variable value is the path to the folder where your JDK is installed, e.g. d:\j2sdk. Note that you may need to restart the computer (or logout of your account then login again) to let the new environment variable take effect.

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 lib folder under your tomcat folder and see whether standard.jar and jstl.jar are there. Sometimes WinZip will create a subfolder under lib (e.g. jarkata-taglibs-standard-1.1.2). If so, find the two jar files in that subfolder and move them to lib.

THE END (or the beginning of a fun class)