O'Reilly logo

Java Servlet & JSP Cookbook by Bruce W. Perry

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.1. Deploying an Individual Servlet on Tomcat

Problem

You want to take a compiled servlet and install it in Tomcat to find out if it is working. You are doing a preliminary test and do not want to take the time to build a complete web application for the servlet.

Solution

Copy and paste the class file into Tomcat's default web application (or into a web application that you have already installed), then request it using the invoker servlet. Or use an Ant build.xml file to move the file temporarily into the Tomcat default web application.

Discussion

Sometimes you design a servlet and are anxious to see if the servlet works. Unless the servlet depends on other servlets or components in the application, you can test it on Tomcat by pasting the class file (including its package-related directories) into the default Tomcat web application. By default, this application is located at the path <Tomcat-installation-directory>/webapps/ROOT.

If the fully qualified class name of the servlet is jspservletcookbook.CookieServlet, then here is the entire process for manually getting a single servlet going on Tomcat:

  • Shut down the Tomcat server by executing the shell script <tomcat-installation-directory>/bin/shutdown or by executing a shell script your server administrator has provided. An alternative is to "stop" the default application by requesting this URL in your browser: http:// localhost:8080/manager/stop?path=/ .

  • Create the jspservletcookbook directory in the <Tomcat-installation-directory>/webapps/ROOT/WEB-INF/classes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required