You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Adrian Beech <a....@optusnet.com.au> on 2002/08/14 06:04:55 UTC

What sort of servlet is required when using it with auto load?

Hi folks,

I would like to put together a servlet that will be used solely for
setting up such things as connection pools, etc.  This servlet will be
auto loaded when Tomcat is started with the appropriate entries in the
web.xml file.  The connection pools will be saved as an application
scoped object for use by various JSP's.  The servlet will not serve up
web content except, I guess, appropriate error messages, etc.  My query
is that what sort of servlet do I need to achieve this?  For example, is
the class an extension of httpServlet, or can it be a simple class that
does not inherit objects from another higher level class?

Are there any examples of this sort of thing floating out yonder?

I am probably the rawest of raw novices when it comes to this sort of
stuff!

Thanks for your patience.

Adrian
a.beech@optusnet.com.au



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: What sort of servlet is required when using it with auto load?

Posted by Ben Walding <be...@walding.com>.
You're probably better off with an application context listener

OnJava has a good article about them:
http://www.onjava.com/pub/a/onjava/2001/04/12/listeners.html


Adrian Beech wrote:

>Hi folks,
>
>I would like to put together a servlet that will be used solely for
>setting up such things as connection pools, etc.  This servlet will be
>auto loaded when Tomcat is started with the appropriate entries in the
>web.xml file.  The connection pools will be saved as an application
>scoped object for use by various JSP's.  The servlet will not serve up
>web content except, I guess, appropriate error messages, etc.  My query
>is that what sort of servlet do I need to achieve this?  For example, is
>the class an extension of httpServlet, or can it be a simple class that
>does not inherit objects from another higher level class?
>
>Are there any examples of this sort of thing floating out yonder?
>
>I am probably the rawest of raw novices when it comes to this sort of
>stuff!
>
>Thanks for your patience.
>
>Adrian
>a.beech@optusnet.com.au
>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
>  
>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: What sort of servlet is required when using it with auto load?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 14 Aug 2002, Adrian Beech wrote:

> Date: Wed, 14 Aug 2002 14:04:55 +1000
> From: Adrian Beech <a....@optusnet.com.au>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
>      a.beech@optusnet.com.au
> To: tomcat-user@jakarta.apache.org
> Subject: What sort of servlet is required when using it with auto load?
>
> Hi folks,
>
> I would like to put together a servlet that will be used solely for
> setting up such things as connection pools, etc.  This servlet will be
> auto loaded when Tomcat is started with the appropriate entries in the
> web.xml file.  The connection pools will be saved as an application
> scoped object for use by various JSP's.  The servlet will not serve up
> web content except, I guess, appropriate error messages, etc.  My query
> is that what sort of servlet do I need to achieve this?  For example, is
> the class an extension of httpServlet, or can it be a simple class that
> does not inherit objects from another higher level class?
>
> Are there any examples of this sort of thing floating out yonder?
>
> I am probably the rawest of raw novices when it comes to this sort of
> stuff!
>

All you need is a servlet that implements only the init() and destroy()
methods, and does *not* implement doGet() or doPost().

If you are running on a Servlet 2.3 or later container (such as Tomcat 4),
however, you have an additional alternative that is actually better --
create a class that implements the javax.servlet.ServletContextListener
interface, and put your setup operations in the contextInitialized()
method to set up your connection pools.  You can also use the
contextDestroyed() method to clean things up later.  The listener class is
declared with a <listener> element in web.xml, as described in the Servlet
2.3 Spec (http://java.sun.com/products/servlet/download.html).

Why is this better than a load-on-startup servlet?  The reason is simple
-- the servlet container makes *no* promises about how long your
load-on-startup sevlet will stay in memory.  The container is free to
remove it, and restart it, at any time during the life of the application.
A ServletContextListener, on the other hand, is guaranteed to be notified
only when the application is actually being started up or shut down.

> Thanks for your patience.
>
> Adrian
> a.beech@optusnet.com.au
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>