Peter Mutsaers wrote:

> Hello,
>
> I have some questions on webapp initialization.
>
> sorry to send this to both tomcat-user and tomcat-dev; since I use
> tomcat 4 I wasn't sure where to send this to. I hope that my questions
> are answered by some brand new, not yet documented features of
> tomcat-4 :)
>
> Browsing through documents, it seems like the only way to create some
> initial objects (such as a JDBC connection pool) in the ServetContext
> is to create a Servlet with load-on-startup, which then in its init()
> method can do some initialization.
>
> This seems a bit clumsy to me, since I don't really need the Servlet
> to handle requests. I just need some hook to initialize my
> ServletContext with some objects.
>
> Are there other (better) ways to do this?
>
> If not: can I force the Servlet to be destroyed after my init() is
> ready?
>
> Another topic: Am I correct in believing that
> ServletContext.getContext(uri) is the only way to obtain stuff from
> another webapps' ServletContext?
>
> In fact what I would like is to create a JDBC Connection Pool to be
> shared amongst various webapps. I could create this pool Object in one
> webapp (via the clumsy Servlet load-on-startup), then copy a reference
> to the ServletContexts of the other webapps. This creates some
> ordering problems (the other webapps may not run until the webapp
> setting up the connection pool is ready).
>
> It would be nicer if Tomcat, before initialising the webapps, would
> offer the possibility for me to run some code. This code (in my case
> creating the pool) should then create some initial context that all
> webapps can access (in order to create a reference in their own
> ServletContext).
>
> I was hoping that in servlet.xml, within the <Host> scope I could
> specify some Object to be shared between all <Context>'s.
>
> Is something like this available?
>
> After a day of searching through specs, mailing-list archives etc I
> hope someone can help me :)
>
> --
> Peter Mutsaers  |  D�bendorf    | UNIX - Live free or die
> [EMAIL PROTECTED]      |  Switzerland  | Sent via FreeBSD 4.3-stable

Hi :-)  I am not sure, the following is from servlet-2_3-pfd2-spec.pdf(for

Servlet containers which supports Servlet spec2.3):

...
SRV.10.2.2 An Example of Listener Use
To illustrate a use of the event scheme, consider a simple web application
containing
a number of servlets that make use of a database. The developer has
provided a serv-let
context listener class for management of the database connection.
1. When the application starts up, the listener class is notified. The
application
logs on to the database, and stores the connection in the servlet context.

2. Servlets in the application access the connection as needed during
activity in
the web application.
3. When the web server is shut down, or the application is removed from
the web
server, the listener class is notified and the database connection is
closed.
...


Bo
May.15, 2001



Reply via email to