Thanks guys,

I've got it all working.

cheers

Jordan

>:O)

-----Original Message-----
From: Andrew Hill [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, 10 December 2002 4:40 PM
To: Struts Users Mailing List
Subject: RE: Initializing application


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
struts-config.

-----Original Message-----
From: Andrew Hill [mailto:[EMAIL PROTECTED]]
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
  {
    try
    {
      ActionServlet servlet =
(ActionServlet)PropertyUtils.getProperty(config,"servlet");
      init(servlet,config);
    }
    catch(Throwable t)
    {
      throw new ServletException("Error in init(config) method",t);
    }
  }

  public void init(ActionServlet servlet, ApplicationConfig config) throws
ServletException
  {
        // 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"/>
  </plug-in>

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 [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 10, 2002 23:16
To: [EMAIL PROTECTED]
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
ServletContext.

David






>From: "Jordan Thomas" <[EMAIL PROTECTED]>
>Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>To: "Struts-User" <[EMAIL PROTECTED]>
>Subject: Initializing application
>Date: Tue, 10 Dec 2002 12:54:27 +0100
>
>Hi,
>
>I want to initialize my application with some application variables. What
>is
>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?
>
>Thanks
>
>Jordan
>
>
>--
>To unsubscribe, e-mail:
><mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail:
><mailto:[EMAIL PROTECTED]>


_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail


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


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


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


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

Reply via email to