You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Howard Miller <h....@admin.gla.ac.uk> on 2002/08/15 15:50:46 UTC

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". 

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?

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

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Initialisation

Posted by Robert Taylor <rt...@mulework.com>.
Howard, look at javax.servlet.ServletContextListener. It is a bootstrap
class for servlet containers. If you wanted to use servlets you could
override ActionServlet.init() or create your own bootstrap servlet or use
Struts plug ins.

I use ServletContextListener because it is a standard way for bootstrapping
web applications and init parameters can be defined in web.xml.

robert

> -----Original Message-----
> From: Howard Miller [mailto:h.miller@admin.gla.ac.uk]
> Sent: Thursday, August 15, 2002 9:51 AM
> To: 'struts-user@jakarta.apache.org'
> 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".
>
> 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?
>
> 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
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Initialisation

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Thu, 15 Aug 2002, Howard Miller wrote:

> Date: Thu, 15 Aug 2002 14:50:46 +0100
> From: Howard Miller <h....@admin.gla.ac.uk>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: "'struts-user@jakarta.apache.org'" <st...@jakarta.apache.org>
> 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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>