There's a requirement to allow code anywhere throughout the application to store and access application-wide state by using a class as shown below. The code cannot directly touch the ServletContext class, but may do so through an interface (shown below).
public class ApplicationState { private static Map<String,Object> stateValues; public static Object getStateValue(String key) { return stateValues.get(key); // return servletContext.getAttribute(key); } } However, I noticed that because the class above is being initialized in a context listener, would you even need to bother using ServletContext? Can't I just take advantage of the fact that the class is being loaded by the application's classloader, and therefore all code within the application (and not other applications) will be able to access the static state of this class? Are there any tradeoffs with using my proposed approach over backing the above class with a ServletContext? Anything to do with the way Tomcat loads classes? Would the answer be different if that class weren't initialized in a context listener, but rather with the first access of ApplicationState happening in a servlet? Thanks. -- View this message in context: http://www.nabble.com/Application-state-in-ServletContext-tf4708314.html#a13457524 Sent from the Tomcat - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]