I have to store a Java object into an application scope. I am to decide
between two possible implementations viz.:
1. use a class with some static properties and some static accessor methods
which can be accessed by any JSP/servlet thread. The shared (application )
object will be there in the static property and will be accessed by the
2. use ServletContext's getAttribute() and setAttribute() methods.Store the values in Application Scope
Well I faced similar issue and here's what I concluded:
1. This should be done only for readonly data. If values are modifiable the they should be read from persistent store always.
2. If you need to cache some data (say from xml files or database) and it is availble at application startup (which is most probable), use servlet context.
And to load the data only use context listener.
3. If data is not availble upon server startup then use static members.