You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by James Howe <jw...@allencreek.com> on 2001/01/08 16:30:37 UTC

Initializing a Struts application

I'm a little confused about how to best initialize some application scope 
information in a Struts application.  For example, I need to configure a 
handful of IP addresses which my beans need to talk to.  I might do 
something like this in a configuration file:

marketData=127.0.0.1

My question is where to put this information.  If I were writing a normal 
servlet application I would probably define this in the init 
operation.  One option I've considered is to subclass from ActionServlet 
and add my own custom initialization tags which I can use in my web.xml 
file.  What I'm trying to figure out is how to best initialize a set of 
application scope variables for my struts application.  Any suggestions 
would be appreciated.

Thanks.


Re: Initializing a Struts application

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
James Howe wrote:

> I'm a little confused about how to best initialize some application scope
> information in a Struts application.  For example, I need to configure a
> handful of IP addresses which my beans need to talk to.  I might do
> something like this in a configuration file:
>
> marketData=127.0.0.1
>
> My question is where to put this information.  If I were writing a normal
> servlet application I would probably define this in the init
> operation.  One option I've considered is to subclass from ActionServlet
> and add my own custom initialization tags which I can use in my web.xml
> file.  What I'm trying to figure out is how to best initialize a set of
> application scope variables for my struts application.  Any suggestions
> would be appreciated.
>
> Thanks.

Subclassing the controller servlet would certainly work, as long as you remember
to call the super.init() method.  You might also do it the way that the Struts
example application does -- a separate servlet (DatabaseServlet) is used to
initialize a bunch of application specific things in its init() method, and the
normal Struts controller servlet is left alone.  You can use the
<load-on-startup> values in your web.xml file to control the order of loading,
if that becomes important.

In a servlet 2.3 environment (such as Tomcat 4.0), you will also be able to use
the new application event listener APIs to catch the contextInitialized() and
contextDestroyed() events.  This will become the preferred method, once servlet
2.3 containers are widely available.

Craig McClanahan