This is the location assumed by the examples in this topic. If you load Tomcat in a different
location, you will need to make appropriate changes to the examples. You may need to set
the environmental variable JAVA_HOME to the top-level directory in which the
Java Development Kit is installed.
To start Tomcat, select Configure Tomcat in the Start | Programs menu, and then press
Start in the Tomcat Properties dialog.
When you are done testing servlets, you can stop Tomcat by pressing Stop in the Tomcat
Properties dialog.
The directory
C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\
contains servlet-api.jar. This JAR file contains the classes and interfaces that are needed to
build servlets. To make this file accessible, update your CLASSPATH environment
variable so that it includes
C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar
Alternatively, you can specify this file when you compile the servlets. For example, the
following command compiles the first servlet example:
javac HelloServlet.java -classpath "C:\Program Files\Apache Software Foundation\
Tomcat 5.5\common\lib\servlet-api.jar"
Once you have compiled a servlet, you must enable Tomcat to find it. This means putting
it into a directory under Tomcat's webapps directory and entering its name into a web.xml
file. To keep things simple, the examples in this chapter use the directory and web.xml file
that Tomcat supplies for its own example servlets. Here is the procedure that you will follow.
First, copy the servlet's class file into the following directory:
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\servlets-examples\WEB-INF\classes
Next, add the servlet's name and mapping to the web.xml file in the following directory:
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\servlets-examples\WEB-INF
For instance, assuming the first example, called HelloServlet, you will add the following
lines in the section that defines the servlets:
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
Next, you will add the following lines to the section that defines the servlet mappings.
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/servlet/HelloServlet</url-pattern>
</servlet-mapping>
Follow this same general procedure for all of the examples.
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home