----- Original Message -----
From: "syed huda" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>


> What are advantages of using ServletContextListener above init()? Don't
they
> do the same thing?

They do not do the same thing. One is scoped at the Application level and
one is at the servlet level.
If your context is running, it is valid for the servlet container to remove
the servlet from service after calling destroy and on receiving a request to
again initialize a new instance of the servlet by calling init(). During
this, the context (application) was up and never went down.

So these help to give control over different lifecycle events.


 Peter Huber wrote
> I think init should be called on startup of the servlet container.
> So if you have very long lasting init procedures better use init.

I fail to see the point here. How does the time taken to execute the
initialization matter here.


Tim Wrote :
> therefore, by the time that contextInitialized is called.. a user may
> already be in the web app. So if ur going to do code like set up db
> connections or something.. it might be too late.

This is exact opposite of what the spec recommends.
I would rather initialize my connection pool in contextInitialized rather
than in init().

Section SRV.10.2.2 of servlet specs 2.3 says
<from specs>

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
servlet 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.

</from specs>

Lot of people here have said this and I concur that the servlet specs are a
very readable document. It can almost solve all your doubts.


Regds,
Gokul

> Regards,
>
> Syed

-----------------------------------------------------------------------------------------------------------------------
Information transmitted by this E-MAIL is proprietary to Wipro and/or its Customers and
is intended for use only by the individual or entity to which it is
addressed, and may contain information that is privileged, confidential or
exempt from disclosure under applicable law. If you are not the intended
recipient or it appears that this mail has been forwarded to you without
proper authority, you are notified that any use or dissemination of this
information in any manner is strictly prohibited. In such cases, please
notify us immediately at mailto:[EMAIL PROTECTED] and delete this mail
from your records.
------------------------------------------------------------------------------------------------------------------------

Reply via email to