[ Team LiB ] |
![]() ![]() |
Recipe 2.2 Using a Context Element in Tomcat'sserver.xmlProblemYou want to deploy and redeploy a servlet on Tomcat 4.1.x without restarting the Tomcat web container. SolutionDeploy the servlet as part of a Context element in Tomcat's server.xml file. DiscussionYou can paste a recompiled servlet class over an existing servlet class and invoke the servlet without restarting Tomcat:
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 the top level of this web application. Most of the example's other attributes have values that are shared by other Contexts. For example, cookies="true" indicates that the Context will use cookies for the session identifier, and crossContext="false" prevents the servlets in this web application from obtaining request dispatchers for other web applications running in the virtual host.
Under this configuration, Tomcat 4.1.x displays a console message after a slight delay when you paste a new servlet class over the old one in the web application. Here is an example of a console message in response to a dynamic servlet reload: WebappClassLoader: Resource '/WEB-INF/classes/com/jspservletcookbook/OracleTest. class' was modified; Date is now: Sun Feb 02 22:17:41 EST 2003 Was: Sun Feb 02 21:38:52 EST 2003 See AlsoThe deployment sections of Tomcat: The Definitive Guide, by Brittain and Darwin (O'Reilly); Recipe 2.1, Recipe 2.4, and Recipe 2.6; Jakarta Tomcat documentation for the Context element: http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/context.html. |
[ Team LiB ] |
![]() ![]() |