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.2. Using a Context Element in Tomcat'sserver.xml

Problem

You want to deploy and redeploy a servlet on Tomcat 4.1.x without restarting the Tomcat web container.

Solution

Deploy the servlet as part of a Context element in Tomcat's server.xml file.

Discussion

You can paste a recompiled servlet class over an existing servlet class and invoke the servlet without restarting Tomcat:

  1. Locate the Context element for your web application or create a new Context element in the <tomcat-installation-directory>/conf/server.xml file. Context elements must be nested within the Host element that represents the virtual host under which your web application is running.

  2. Set the reloadable attribute of your Context element to true. This signals Tomcat to monitor the contents of WEB-INF/classes and WEB-INF/lib for any changes. If changes are detected, Tomcat automatically reloads the web application.

The Context element in server.xml looks like this:

<Context className="org.apache.catalina.core.StandardContext" 
         crossContext="false"reloadable="true" 
         mapperClass="org.apache.catalina.core.StandardContextMapper" 
         useNaming="true" debug="0" swallowOutput="false" 
         privileged="false" displayName="Home Web App" 
         wrapperClass="org.apache.catalina.core.StandardWrapper" 
         docBase="h:\home" cookies="true" path="/home" 
         cachingAllowed="true" 
         charsetMapperClass="org.apache.catalina.util.CharsetMapper"
>

The path attribute represents the context path for the application. The docBase attribute points to the directory that represents ...

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