tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin HaleBoyes <>
Subject Re: A servlet which has no mapping?
Date Tue, 16 Oct 2001 12:17:37 GMT
> I am creating a servlet class which extends HttpServlet, but it will
> only implement the init() and destroy() methods.  It won't have a
> doGet() or any other do*() method.  Its only purpose it to set up a DB
> connection pool for use by the custom tag libs.

I used that method initially for my application and it worked great.
I think there are some issues that you have to watch concerning load
order and shutdown (don't know, just speculating).  I've also seen people
mention that it isn't very "portable" across other containers.

A new mechanism was added (to 2.3??) that addresses these problems:
   Lifecycle events & a ServletContextListener

I now have a class in my application:
  public final class DataSourceInitServlet
                    implements  ServletContextListener

that has a method:
    public void contextInitialized( ServletContextEvent event )

This method gets called (a Lifecycle event) when the context has just been
created and is available to service requests (or something like that).

You have to also add the <listener> clause to the web.xml file:

Anyway, I put all my DB initialization into that method.  There is a
corresponding method contextDestroyed() for shutdown Lifecycle events.

Have a look at the servlet spec in chapter 10 and in the archives.


Do You Yahoo!?
Get your free address at
or your free address at

View raw message