struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Hill" <andrew.david.h...@gridnode.com>
Subject RE: Initializing application
Date Tue, 10 Dec 2002 15:35:54 GMT
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:dgraham1980@hotmail.com]
Sent: Tuesday, December 10, 2002 23:16
To: struts-user@jakarta.apache.org
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" <jot@ipa.fraunhofer.de>
>Reply-To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
>To: "Struts-User" <struts-user@jakarta.apache.org>
>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:struts-user-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail:
><mailto:struts-user-help@jakarta.apache.org>


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


--
To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message