wood burning stoves 2.0*
The moose likes Tomcat and the fly likes Servlet container scope variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Servlet container scope variable" Watch "Servlet container scope variable" New topic
Author

Servlet container scope variable

David Sheltby
Ranch Hand

Joined: Oct 19, 2011
Posts: 34
Is there a solution for creating property variables that are container-scoped (available to all web-applications). I'm sure there is but I can't seem to find any docs for this. Can these properties be db driven in any way?

Thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

This is not supported in the J2EE or JEE standards. The widest property scope that the standards address is Application Scope.

Effectively, each webapp in a J(2)EE container is the only webapp in the JVM. Each webapp has its own individual classpath, so sharing static class properties between webapps can be problematical, especially considering that some of the JVM implementors have been experimenting with things that may raise that wall even higher.

There are some tricks that can be used. For example, shared sessions, although they are per-user cross-application objects. You can create shared class libraries and place them in the TOMCAT_HOME/lib directory, but it will be up to you to provide your own access methods and thread-safe access. Both of these tricks require not only stepping outside of the standards, but also special configuration of the webapp server itself.

A more standardized approach would be to implement shared objects as EJBs. Although Tomcat itself does not implement EJBs, there are ways to get around that. EJBs were originally specifically designed to allow applications to share data not only across applications, but also across JVMs. The original mechanisms were fairly cumbersome, but EJB3 has simplified things a lot.

While working with EJBs isn't quite as simple as working with property sets, you could front a set of EJBs with a Property manager. It wouldn't be quite the same as the standard scope sets, but it would be close enough for comfort, I think.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet container scope variable