Java Reference
In-Depth Information
Want to know the big secret from the 1973 film
Soylent Green
?
Decode this ROT-13 text: Fbba gurl'yy or oerrqvat hf yvxr pnggyr!
Lbh'ir tbg gb jnea rirelbar naq gryy gurz! Fblyrag terra vf znqr bs
crbcyr! Lbh'ir tbg gb gryy gurz! Fblyrag terra vf crbcyr!
NOTE
To make the ROT-13 servlet available, you must publish its class files in a folder on your
web server that has been designated for Java servlets.
Tomcat is organized so that servlets, other classes, and JSP pages are placed in subfold-
ers of the software's
webapps
folder. One way to deploy a servlet's class file is to store it
in a
WEB-INF\classes
subfolder somewhere in the
webapps
hierarchy of folders.
If you chose to install them during installation, Tomcat 5.5 includes several sample
servlets in the
servlets-examples
and
jsp-examples
folders inside
webapps
. You can
deploy the ROT-13 servlet in the
servlet-examples
folder by storing
Rot13.class
in
webapps\servlet-examples\WEB-INF\classes
(Windows) or
webapps/servlet-
examples/WEB-INF/classes
(Linux).
If you place the
Rot13.class
file in this folder, edit the
web.xml
file in its parent folder
and add the following lines:
<servlet>
<servlet-name>Rot13</servlet-name>
<servlet-class>Rot13</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Rot13</servlet-name>
<url-pattern>/servlet/Rot13</url-pattern>
</servlet-mapping>
The
web.xml
file configures a web application such as the group of servlet examples
stored in
wepapps\servlet-examples
.
These lines must be placed somewhere after the opening
<web-app>
tag and before the
closing
</web-app>
tag.
After adding the class file and editing
web.xml
, restart Tomcat and run the servlet by
loading its address with a web browser.
The address of the servlet depends on where it was stored in the
webapps
folder. If you
used the preceding configuration, it's in
/servlets-examples/servlet/Rot13
, as in
http://localhost:8080 /servlets-examples/servlet/Rot13.