tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: servlets have their own web app context?
Date Fri, 01 Sep 2000 19:32:14 GMT
"Shade, Christopher" wrote:

> thanks for clearing that up!  but is it true that the only way to do this in
> Tomcat is to change the root in server.xml to match the path where the JSPs
> are, because the /servlet has the root context?  is there a way for me to
> invoke a servlet using something like
> /whsp/servlet/com.blah.blah.SubscriberServlet while /whsp is a defined web
> app?
> thanks again, ...cxs

Look at the "examples" context that comes with Tomcat, and you'll see that you
are not limited to putting servlets only in the root.  For example, the Hello,
World example is executed by requesting:


The reason this works is because of how request parsing is done:

* First, Tomcat identifies the context path ("/examples").  This is used
  to figure out what document root to use, and from there what web.xml
  file applies to this webapp.

* Next, it matches the rest of the path ("/servlet/HelloWorldExample")
  against all the <servlet-mapping> entries you have defined, including
  the default ones.

* It turns out that there is a mapping (with URL pattern "/servlet/*")
  to a Tomcat-provided servlet called the "invoker" servlet.  This servlet
  looks at the rest of the path ("/HelloWorldExample") and assumes that
  it is the name of a Java class that implements Servlet.  Then, it loads
  up your servlet and executes it.

Thus, to make your servlets available to a context called "/whsp", all you have
to do is put your servlet classes into
"$TOMCAT_HOME/webapps/whsp/WEB-INF/classes", or in a JAR file in
"$TOMCAT_HOME/webapps/whsp/WEB-INF/lib".  These servlets will be accessible at
URL like:


Craig McClanahan

See you at ApacheCon Europe <>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat

View raw message