Using the Tomcat Web Server

CIS 451/551 and 452/552

Get a Port Number

Look at the list of port assignments for the class. This is your own port number for the term.


Install Tomcat

Setup your java environment for compiling servlet (or use the bash equivalent):
setenv CLASSPATH $PATH
setenv CLASSPATH ${CLASSPATH}:/local/apps/WWW/jakarta-tomcat-5.0.18/common/lib/servlet-api.jar

You will be using three scripts (located in /local/bin), which run only on ix:

To install tomcat, when on ix, run install_tomcat 5.0.18. It will ask for your port number - please be sure you give it the correct value. It will create a directory called tomcat-5.0.18 in your home directory and populate it with examples. The default version is 5.5, which we've had problems with so you MUST specify the version number.

You will then need to start tomcat (using the script). Should you ever need to restart it, be sure to stop it first. The above is further documented on a page by the departmental systems staff (under software): the Quickstart Guide: Tomcat.

Test your own server, after it's started, by going to the URL http://ix.cs.uoregon.edu:your-port-number/index.html (for href="http://ix.cs.uoregon.edu:9001/index.html"example) and running the servlet examples. You can see the examples in your tomcat-5.0.18/webapps/examples/WEB-INF/classes directory.


Running Your Own Servlets

There are many places you might be able to put the servlets. A simple way:
  1. Put the .class files into your tomcat-5.0.18/webapps/examples/WEB-INF/classes directory.
  2. You must register in the associated .../WEB-INF/web.xml file defining both a new servlet and servlet mapping for each class file you add. This must be updated only once for each class you add.
  3. Stop and restart the tomcat server (this should only be necessary if your server is not responding). This must be done every time you recompile the java file in order to see the changes. This should take 10-30 seconds.
  4. Invoke the servlet, for example Hello.class, with the URL http://ix.cs.uoregon.edu:your-port-number/servlets-examples/servlet/HelloWorldExample link.
You can see some examples. Note that there we created a directory tomcat-5.0.18/webapps/cis451, containing WEB-INF/classes, into which the class files were put.

Writing and Compiling Your Own Servlets

We will not tell you how to write servlets, leaving that to the examples and web links. To compile, first get your environment variables setup properly. Then, to compile Hello.java, just type javac Hello.java


Tomcat Documentation

See the links page for what we have.