tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Auto start servlets in Tomcat 3.2
Date Mon, 04 Dec 2000 00:41:21 GMT
Paul Mendelson wrote:

> I am trying to have a servlet start automatically in Tomcat 3.2.
> In Tomcat 3.1 I created a servlet entry in web.xml and everything went fine.
> In Tomcat 3.2 they provide a sample web.xml file but it refers to a class,
> org.apache.tomcat.servlets.InvokerServlet, that does not seem to be part of
> Tomcat anymore.

> My questions are:
> is web.xml still the proper way to introduce servlets that should start when
> Tomcat starts?

Yes, but you have to use the file in WEB-INF/web.xml under your own web
application's document root.  The global one is no longer processed in 3.2 --
4.0 returns to this behavior because it was a very convenient way to deal with
global defaults.

However, the web.xml for each individual application is indeed processed.

> If web.xml is the vehicle, what is the correct syntax for the block:
>     <servlet>
>         <servlet-name>
>             invoker
>         </servlet-name>
> <!--
>             org.apache.tomcat.servlets.NoInvokerServlet
> -->
>         <servlet-class>
>             org.apache.tomcat.servlets.InvokerServlet
>         </servlet-class>
>     </servlet>
> OR
> When I take out that section my servlets don't run at all?

Note that the invoker mechanism has nothing at all to do with whether a servlet
is loaded at startup time.  Instead, you will create an entry like this in your
WEB-INF/web.xml file:



Now, this servlet will be loaded at startup time, and you can execute it with a
URL like this (assuming "/myapp" is the context path of your webapp):


Note that the following URL will also execute this servlet:


but this approach is not necessarily portable.  The "invoker" mechanism (the
thing that processes "/servlet/*" type URLs) is not part of the servlet
specification, and is therefore not guaranteed to be present, or implemented
identically, in all versions of all servlet containers.

I recommend that you learn about the power that servlet mappings give you to
control what URLs get assigned to your own servlets.  You can read the basic
rules in the Servlet API Specification, which can be downloaded from:

or in any of the books and magazine articles starting to appear that cover the
version 2.2 servlet API.

> Thanks in advance,
> Paul

Craig McClanahan

View raw message