Create an object which implements ServletContextListener interface.
Drop it in the /WEB-INF/class directory or /WEB-INF/lib directory if you are
jarring your classes.
Defined the listener in web.xml.

For example, let's say I have an object which implements
ServletContextListener interface called,
MyServletContextListener in package com.company.application.

Place the following in web.xml
<listener>

<listener-class>com.company.application.MyServletContextListener</listener-c
lass>
</listener>

And yes, the class will be invoked automatically when the servletcontainer
cranks up the web app up.
It's that easy.

Place your initialization code in

public void contextInitialized(ServletContextEvent event) {

        // put init code here

}

The ServletContextEvent gives you access to the ServletContext.

robert

> -----Original Message-----
> From: Howard Miller [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 15, 2002 10:14 AM
> To: 'Struts Users Mailing List'
> Subject: RE: Initialisation
>
>
> Errrr.....
>
> sorry, out of my depth again. I read the documentationfor
> ServletContextListener, and I'm not sure... Does this mean that all I have
> to do is implement the interface, drop the .class file in WEB-INF/classes
> and that's it... the code will run when the servlet starts up? Sounds too
> easy!
>
> How do I override the ActionServlet.init(). I can write the code but where
> do I put it?
>
> Bootstrap servlet - what's that?
>
> Plugins - Is there any documentation?
>
> So many questions - sorry!
>
> -----Original Message-----
> From: Robert Taylor [mailto:[EMAIL PROTECTED]]
> Sent: 15 August 2002 14:58
> To: Struts Users Mailing List
> Subject: RE: Initialisation
>
>
> 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:[EMAIL PROTECTED]]
> > Sent: Thursday, August 15, 2002 9:51 AM
> > To: '[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".
> >
> > 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:
> > <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