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
- 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.
- 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
- Download this file web.xml
to the directory
tomcat\webapps\netprog\WEB-INF.
- Download this file CurrencyConverter.html to the tomcatwebapps\netprog directory.
- Restart tomcat
- With your favorite web browser, go to
http://localhost:8080/netprog/CurrencyConverter.html and enter a dollar value
Deploying a simple jsp
- Download the file
CurrencyConverter.jsp to the tomcat
\webapps\netprog directory.
- Edit the CurrencyConverter.html file, changing the
string action=/servlet/CurrencyConverter to action=CurrencyConverter.jsp
- With your favorite web browser, go to
http://localhost:8080/netprog/CurrencyConverter.html
Deploying a jsp which uses a Bean
- Compile the file
CurrencyConverterBean.java
- Create a new subdirectory called converters in
tomcat\webapps\netprog\WEB-INF\classes
and copy the file CurrencyConverterBean.class to this
new subdirectory
- 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.
- Edit the file CurrencyConverter.html to change the
action of the form to CurrencyConverter2.jsp
- Start up tomcat.
- With your favorite web browser, go to
http://localhost:8080/netprog/CurrencyConverter.html