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