I actually went the plug-in route, that seems to work very nicely. Is there any benefit of a ContextListener vs. a plug-in? The only obvious one that comes to mind is that a plug-in is Struts-specific, so your tied to that framework, but that seems a pretty smalll consideration since there's plenty more that ties you to Struts as an app is developed. Thanks!


From: "Jacob Weber" <[EMAIL PROTECTED]>
Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Subject: Re: App-level globals
Date: Mon, 17 May 2004 12:32:18 -0400

You can make a ContextListener class like this:

public final class MyContextListener
   implements ServletContextListener {
   private ServletContext context = null;
   public BaseServletContextListener() {}
   public void contextInitialized(ServletContextEvent event) {
      this.context = event.getServletContext();
      // run your initialization routine here
   }
   public void contextDestroyed(ServletContextEvent event) {
      this.context = null;
   }
}

and put this in your web.xml:
<listener>
   <listener-class>path.to.MyContextListener</listener-class>
</listener>

Jacob

----- Original Message -----
From: "None None" <[EMAIL PROTECTED]>
Newsgroups: gmane.comp.jakarta.struts.user
Sent: Monday, May 17, 2004 12:17 PM
Subject: App-level globals


> Hello again everyone... I am starting conversion of a none-Struts app to
> Struts, and mostly it's straight-forward, but two things I have questions
> about...
>
> The home-grown framework this app was written with has the notion of an
App
> Loader. Basically, this is a class that runs at startup and reads in some
> config information and stores it in a static config object. The
properties
> of this object are referenced throughout the app.
>
> The other concern is that this same process spawns a couple of
low-priority
> background threads to do some various things throughout the lifetime of
the
> app.
>
> My question, which I have been unable to find an answer to on my own, is
if
> Struts has a similar startup "initialization" mechanism? If not, do I
> simply create my own servlet to do all this work and set it to run on
> startup in web.xml? I have no problem with the later approach, but I'm
> wondering if Struts has a mechanism for this, like our custom framework
> does?
>
> Thanks all!
>
> _________________________________________________________________
> Express yourself with the new version of MSN Messenger! Download today -
> it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/




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


_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar – get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/



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



Reply via email to