struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Hill" <>
Subject RE: Initializing application
Date Tue, 10 Dec 2002 15:39:54 GMT
Oh yeh. Almost forgot.
Plugins are called when your webapp is initialised (before anyone can access
it) and are executed serially in the order you listed them in your

-----Original Message-----
From: Andrew Hill []
Sent: Tuesday, December 10, 2002 23:36
To: Struts Users Mailing List
Subject: RE: Initializing application

Another idea would be to make use of a struts plugin. These are actually
very simple to write!

Just implement PlugIn and its init() method and add to struts-config and
bobs yer uncle.

btw: the signature of the init method changed between 1.1b1 and 1.1b2. If
you do the following trick your Plugin should work in both environments (I
havent tested it though!):

  public void init(ApplicationConfig config) throws ServletException
      ActionServlet servlet =
    catch(Throwable t)
      throw new ServletException("Error in init(config) method",t);

  public void init(ActionServlet servlet, ApplicationConfig config) throws
	// your code here

(Why I dont just use getServlet() escapes my memory. Maybe the later version
doesnt have a getServlet() in the config object?)

To add to your struts config (right down near the end of it):
<plug-in className="com.mypackage.MyPlugIn">
    <set-property property="bob" value="a job"/>

the set-property tags are optional, but you can use them to pass parameters
to your plugin (in which you would define a setBob() method....)

-----Original Message-----
From: David Graham []
Sent: Tuesday, December 10, 2002 23:16
Subject: Re: Initializing application

You can define context-params in your web.xml file that will be application
init variables.  You could also setup a servlet to be loaded when the
container starts and put the code in the init() method.  See the javadocs on
the servlet.init() method it's pretty easy to get ahold of the


>From: "Jordan Thomas" <>
>Reply-To: "Struts Users Mailing List" <>
>To: "Struts-User" <>
>Subject: Initializing application
>Date: Tue, 10 Dec 2002 12:54:27 +0100
>I want to initialize my application with some application variables. What
>the best way to do this? My approach so far has been to call the init()
>method in an unmapped servlet. So everytime the server statrs up they are
>loaded into memory. The only thing is that I am not sure how to set an
>application or session variable in the init method of a servlet. How can I
>do this? Is there a better way to do this?
>To unsubscribe, e-mail:
>For additional commands, e-mail:

The new MSN 8: smart spam protection and 2 months FREE*

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message