Or you could just do what you are currently doing, but not define Hashtable instead 
the static initializer, but define it as public static Hashtable at the class level 
and then simply initialize it in the static initializer...much more simple and 
straightforward

>>> [EMAIL PROTECTED] 8/3/00 1:22 >>>
Hi,

take a look at the Singleton pattern.

ron


--- Oren Klichevsky <[EMAIL PROTECTED]>
wrote:
> I think that you should approach the problem from
> another direction.
> Create a bean that will do all the initilization of
> the Hashtable on it's
> instantiation.
> After that use your bean with the "application"
> scope within your JSP files.
> This will assure you that this bean will be
> inistantiated only one time for
> the whole application. After doing that you will be
> able to use all the
> regular bean syntax of JSP to access it's data.
>
>
> Best Regards,
> Oren Klichevsky
> www.mannainc.com <http://www.mannainc.com>
>
>
>
> -----Original Message-----
> From: A mailing list about Java Server Pages
> specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of
> Dowd, Brian
> Sent: Thursday, August 03, 2000 6:12 PM
> To: [EMAIL PROTECTED]
> Subject: static initialiser block in JSP page
>
>
> HI All,
>    I'm trying to get a static initializer in my JSP
> page (such that it will
> only ever populate
> a hashtable once in the java file generated).
> Something *like* this :
>
> <%!
>     String code = "X";
>
>    // static initialiser block to construct
> hashtable (once ever).
>    static {
>         Hashtable months = new Hashtable();
>                 // These values come from the region
> table in ARM.
>         regions.put("0", "January");
>         regions.put("2", "February");
>
>         // .... etc
>
>    }
>
> %>
>
>
> <%
>      // Use a month
>     out.println("Jan=" + (String) regions.get("1"));
>
> %>
>
>
> It works if I move it out of the <%! .. %> tags and
> make it a non static,
> but the
> point is I want it to be static .... has anyone done
> anything similar ?
>
> Cheers,
> Brian.
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with
> body: "signoff
> JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>
>
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with
> body: "signoff JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets


__________________________________________________
Do You Yahoo!?
Kick off your party with Yahoo! Invites.
http://invites.yahoo.com/

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to