Tomcat Exercises

This is a three part exercise on tomcat. The first part shows you how to deploy a servlet, the second shows you how to deploy a jsp without reference to any other classes, and the third part shows you how to deploy a jsp which references a bean. These all assume that you have downloaded and installed the latest version of Tomcat (5.5).

Alert: When you click on the files with an xml, html, or jsp suffix, your browser tries to execute them, and so you will not see the raw text. You can view the source in notepad or whatever and save it to a file.

Deploying a servlet

  1. Download this program: CurrencyConverter.java. Compile it with javac. Note that you are using special servlet classes, so you need to compile with this option -classpath tomcat\common\lib\servlet-api.jar replacing tomcat with your tomcat directory.
  2. In your tomcat webapps directory, create a subdirectory called netprog. In the netprog directory, create a subdirectory called WEB-INF. In this WEB-INF directory, create a subdirectory called classes
  3. Download this file web.xml to the directory tomcat\webapps\netprog\WEB-INF.
  4. Download this file CurrencyConverter.html to the tomcatwebapps\netprog directory.
  5. Restart tomcat
  6. With your favorite web browser, go to
    http://localhost:8080/netprog/CurrencyConverter.html and enter a dollar value

Deploying a simple jsp

  1. Download the file CurrencyConverter.jsp to the tomcat \webapps\netprog directory.
  2. Edit the CurrencyConverter.html file, changing the string action=/servlet/CurrencyConverter to action=CurrencyConverter.jsp
  3. With your favorite web browser, go to
    http://localhost:8080/netprog/CurrencyConverter.html

Deploying a jsp which uses a Bean

  1. Compile the file CurrencyConverterBean.java
  2. Create a new subdirectory called converters in tomcat\webapps\netprog\WEB-INF\classes and copy the file CurrencyConverterBean.class to this new subdirectory
  3. Copy the file CurrencyConverter2.jsp to the directory tomcat\webapps\netprog Note that when you click on this in your browser, nothing much appears, but if you look at the source in notepad or whatever, you can see and save the contents.
  4. Edit the file CurrencyConverter.html to change the action of the form to CurrencyConverter2.jsp
  5. Start up tomcat.
  6. With your favorite web browser, go to
    http://localhost:8080/netprog/CurrencyConverter.html