On Thu, 27 Jun 2002, Heligon Sandra wrote:
> Date: Thu, 27 Jun 2002 09:35:09 +0200
> From: Heligon Sandra <[EMAIL PROTECTED]>
> Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]>
> To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
> Subject: ActionServlet init() method vs ServletContextListener API
>
>
> Hi,
>
> The Servlet 2.3 specification provides a mechanism to be notified
> when
> the application start-up: the ServletContextListener API.
> What is the best solution for single initialisations ? Is it in our
> own ServletContextListener class
> or in the init() method of the ActionServlet subclass.
> I am not sure, the ActionServlet init() method is called once, isn't
> it ?
If you are on a Servlet 2.3 or later system, ServletContextListener should
be the preferred approach.
The reason for this is that the servlet spec does *not* guarantee that a
servlet will be loaded once and then left in memory the entire lifetime of
the app, although in principle most containers do that for heavily
requested servlets. For example, it is entirely legal for a container to
throw out the Struts controller servlet, and then re-initialize it again,
as many times as it wants to, within the lifetime of a webapp.
The nice thing about ServletContextListener is that you're guaranteed that
contextInitialized() and contextDestroyed() are only called at the times
you need them (webapp startup and webapp shutdown), no matter what happens
with servlets and JSP pages in the middle. But this only works on a 2.3
or later system, where this API was added.
>
> Thanks in advance.
> Sandra
Craig
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>