You still can, because for example you will have a servlet that will loaded up more 
than once.

Or if you have a pre-check that checks for null and then loads it up in app context, 
it will work once per jvm (not sure exactly if it is once per server or jvm).

Internationalization may be an issue however.

sandeep

-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] Behalf Of Jacob Weber
Sent: Sunday, May 09, 2004 9:06 AM
To: [EMAIL PROTECTED]
Subject: Storing global data in the servletContext



I have a lot of data that needs to be available to all users, at any 
time (for example, the contents of drop-down menus, which I loaded from 
an XML file). From all the posts I've seen here, the recommended place 
to store global data seems to be the servletContext. Most people are 
setting up a ServletContextListener, and loading this data in the 
contextInitialized method.

But according to the servlet spec 
(http://jcp.org/aboutJava/communityprocess/final/jsr154/index.html), 
page 32:

"Context attributes are local to the JVM in which they were created. 
This prevents ServletContext attributes from being a shared memory store 
in a distributed container. When information needs to be shared between 
servlets running in a distributed environment, the information should be 
placed into a session (See ChapterSRV.7, ³Sessions²), stored in a 
database, or set in an Enterprise JavaBeans TM component."

I'm going to be running in a cluster...does this mean that I can't use 
the servletContext? If that's the case, I have two other questions:
 - When do I first put the data into the session? I don't think I have 
access to it in the ServletContextListener.
 - How do I prevent it from being replicated for all users?

Another question: I may have 50 or so pieces of data. When I store them 
(in either the session or the servlet context), would you recommend 
putting them all in as separate attributes, or wrapping them all into 
one bean and just storing that one bean as an attribute? Or does it not 
matter?

Thanks for any help.
Jacob


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to