I didn't mention that part :-)

Obviously, there's no point in tomcat calling the
doGet/doPost methods - they're meant to be
passed in data about the calling browser etc.,
and output an HTML page. That just doesn't
make sense in the "load-on-startup" situation.

You define (actually, over-ride) the init method of
the servlet instead, like this:

public void init(ServletConfig config) throws ServletException 
{
    super.init(config);
  // put your startup code here, like creating java objects and
  // putting them in the application context where all jsp pages
  // and other servlets can get at them.
  // 
  // eg
  //
  // ServletContext context = config.getServletContext();
  // SystemState systemState = new SystemState();
  // context.setAttribute("systemState", systemState);

}   

This is all documented in the sun java servlet specifications...

Regards,

Simon

> -----Original Message-----
> From: Nicolás Marjovsky [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, December 28, 2000 7:57 PM
> To:   [EMAIL PROTECTED]
> Subject:      Re: context initialization
> 
> Dear Simon:
>     I've tried what you told me but the servlet doesn´t gets executed,
> it´s
> just preloaded.
> 
> Any ideas?
> 
> Thanks for your help,
> Nicolás
> 
> ----- Original Message -----
> From: "Kitching Simon" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, December 27, 2000 7:16 AM
> Subject: RE: context initialization
> 
> 
> If I understand your question correctly, I do this sort of
> thing currently, by having a servlet which instantiates
> a bunch of objects, and adds them to the context.
> This servlet is defined as "load-on-startup".
> 
> 
> In the webapp's web.xml, I have:
> 
>     <!-- define a servlet/class that can be accessed by all other
> components
> -->
>     <servlet>
>         <servlet-name>initializerServlet</servlet-name>
>         <servlet-class>orange.ola3.InitializerServlet</servlet-class>
>         <load-on-startup>1</load-on-startup>
> 
>         <init-param>
>           <!-- set system state mode. Valid values are:
>                PRODUCTION, TEST, DEBUG
>           -->
> 
>           <param-name>systemStateMode</param-name>
>           <param-value>DEBUG</param-value>
>         </init-param>
>     </servlet>
> 
> In reality, I have a whole bunch more init-param tags, containing things
> like JDBC connection strings.
> The servlet code itself does a bunch of things like:
> 
>           systemState = new SystemState();
>           context.setAttribute("systemState", systemState);
> 
> Regards,
> 
> Simon
> 
> > -----Original Message-----
> > From: Nicolás Marjovsky [SMTP:[EMAIL PROTECTED]]
> > Sent: Tuesday, December 26, 2000 10:40 PM
> > To: [EMAIL PROTECTED]
> > Subject: context initialization
> >
> > Hello,
> > I need to put some static objects into a web application context at
> > start-up time... I want to set the context when the application is going
> > up. Where should I put this? In web.xml?
> >
> > Thanks,
> > Nicolás
> 

Reply via email to