On Thu, 28 Nov 2002, Rasputin wrote:

> Date: Thu, 28 Nov 2002 01:19:24 +0000
> From: Rasputin <[EMAIL PROTECTED]>
> To: Craig R. McClanahan <[EMAIL PROTECTED]>
> Cc: [EMAIL PROTECTED]
> Subject: Re: setting Context attributes in web.xml/server.xml?
>
> * Craig R. McClanahan <[EMAIL PROTECTED]> [1125 20:25]:
>
> > > Lovely, that's the sort of mechanism I was looking for - is it portable
> > > between servlet containers though?
>
> > ServletContextListener is indeed portable to any Servlet 2.3 or later
> > container.
> >
> > APIs that start "java." or "javax." are portable (although sometimes
> > version specific), while APIs that start "org.apache." are not portable.
>
> Right, thanks. It's more elegant, so is probably The Right Thing...
>
> > > For the record, the load-on-startup hack works pretty well. Cheers.
>
> > Load-on-startup is indeed a hack (although it's about the only way to do
> > this for pre-Servlet-2.3), because there is no guarantee that the servlet
> > container will leave your servlet in memory for the lifetime of the web
> > application.
>
> Damn, I was folowing all this up until you said that :)
>
> Unless I've got this back-asswards, once the Attribute is saved in
> the ServletContext ( which happens in init() ), won't it stay there?
> I thought that was the point of a ServletContext?
>       Sure, it'll vanish when the server restarts, but if the
> WorkAround servlet init() method replaces it during 'load-on-startup',
> it shouldn't matter, should it?

It will stay in the ServletContext attributes until you remove it, or
until the web application is shut down.

Most people who set things up in the init() method of a load-on-startup
servlet will also clean up after themselves in the destroy() method of the
same servlet -- for example, if you open a database connection at startup,
you generally want to close it at shutdown.  With a load-on-startup
servlet, there are no guarantees how many times this might happen during
the lifetime of your application.  With contextInitialized() and
contextDestroyed() methods of ServletContextListener, you get that
guarantee.  That's why the latter is better.

Craig


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to