to tell your container to load a servlet on startup, use this block in
your web.xml file:

<servlet>
  <servlet-name>SomeServlet</servlet-name>
  <servlet-class>fully.qualified.package.SomeServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>


in your startup servlet:

public void init() {
    // do some parsing and build your array

    //set your array in the servlet context
    getServletContext().setAttribute("someKey", yourArray);
}

in any jsp within this application context:

<%
    String[] yourArray = (String[])application.getAttribute("someKey");
    //do something with yourArray
%>

hope this helps...

VIAUD Cédric wrote:

>
>
> I think you can do your initialisation in the init() method of the
> servlet.
>
> Cédric
>
> -----Message d'origine-----
> De : struts (H2Opilot) [mailto:[EMAIL PROTECTED]]
> Envoyé : mercredi 12 septembre 2001 10:41
> Ŕ : [EMAIL PROTECTED]
> Objet : AW: Initalizing at startup and make global usable
>
> hi,
> this was also my Idea, but I still down't know how to start the
> servlet in
> the XML.
> And I also down't know how to set the Array's with in the java-Class
> file.
>
> And later I down't know how to reuse the Array's in the jsp-File to
> forward
> it to the jsp-file witch is producing the menue via out.println.
>
> Can U give me a simple Code-Example?
>
> -----Ursprüngliche Nachricht-----
> Von: Alexander Jesse [mailto:[EMAIL PROTECTED]]
> Gesendet: Mittwoch, 12. September 2001 10:31
> An: struts-user; struts
> Betreff: RE: Initalizing at startup and make global usable
>
> hi,
>
> write a little servlet that parses the config-file, set up your bean
> and store it in the application-context.
>
> In your jsp's you can then access it with scope="application", which
> is
> fast!
>
> To get your servlet executed at start-time, you can define it in your
> web.xml with a "load-at-startup"-parameter. Then it will be started by
> the
> servlet-engine as soon as it is ready.
>
> hope this helps
> Alexander
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 12, 2001 10:14 AM
> To: [EMAIL PROTECTED]
> Subject: Initalizing at startup and make global usable
>
> Hi all,
> I have to use an Array with my menuestructur global in my
> strutsapplication.
> Therefor I implement an Class DynamicBean which initalizes the Array
> and
> fills them all up by parsing an config file.
>
> Up to now I put this call at any *.jsp-page. This is quite slow,
> because he
> always should read the full config file and parse it for any jsp.
>
> Here is my code example:
>
> <% h2ouapp.DynamicBean menu= new h2ouapp.DynamicBean();%>
>
> The constructor of this Class is then initalizing the array..
>
> I then use this Array via the following call to produce the menue:
>
> <% out.println(menu.moschreib());%>
>
> So, how can I start the initalizing via startup of struts...
> Should I use web.xml?
> How can I make the array global accessible and can I then use it?
>
> Can anybody give me a code example?


Reply via email to