On Thu, 15 Aug 2002, Howard Miller wrote:

> Date: Thu, 15 Aug 2002 14:50:46 +0100
> From: Howard Miller <[EMAIL PROTECTED]>
> Reply-To: Struts Users Mailing List <[EMAIL PROTECTED]>
> To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
> Subject: Initialisation
>
> Errr... stupid newbie question coming up.
>
> If I want to create objects in the Application Scope the design notes for
> Struts says.... "application scope beans are initialized in the init()
> method of a startup servlet".
>

Well, they *can* be done there, and it's very common.  But this is not the
only choice.  Application scope attributes can be created at any time.

> But, and I'm sure I'm missing something here, I haven't got an init() method
> because the servlet belongs to Struts. So where do I put my innitialisation
> code?
>

In Struts 1.0.x, the common pattern is to subclass ActionServlet and
override the init() method for this kind of thing:

  public class MyActionServlet extends ActionServlet {

    public void init() throws ServletException {

      // Perform standard Struts initialization
      super.init();

      // Perform my extra initializations
      ...

  }

}

In Struts 1.1, you have the additional option of creating a PlugIn
implementation and registering it in your struts-config.xml file.  A
PlugIn has init() and destroy() methods very similar to a servlet, and are
called at startup and shutdown times as you would expect.  You can have as
many PlugIn instances as you need.

The struts-example webapp in 1.1 uses a PlugIn to set up and shut down its
pseudo-database.  Take a look at the included sources to get an idea of
how it all fits together.

> I noticed plugins in earlier posts, but there isn't any documentation that I
> can find - is this what I'm looking for?
>
> Sounds like a fundamental thing to want to do, which is why I'm sure I'm
> missing something really obvious!
>
> Cheers...
>
> Howard
>

Craig


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

Reply via email to