aspose file tools*
The moose likes Servlets and the fly likes Sharing variable across applications? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Sharing variable across applications?" Watch "Sharing variable across applications?" New topic
Author

Sharing variable across applications?

Ivan Jouikov
Ranch Hand

Joined: Jul 22, 2003
Posts: 269
Is there any direct way to do that, other than some DB-workaround?

I noticed in Tomcat administration there's an "Environment Entries" section, which has some values. Could that be it?
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
You can get a reference to another application's ServletContext like this:

this.getServletContext().getContext(uriPath);

Then, you can save an attribute into that context. Just remember, servlet context attributes are not inherently thread safe!


Anthony W.<br />MCP, SCJP 1.4, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
You could also use the above described method but instead of putting a variable into the servlet context, you put the variable into request context, get a RequestDispatcher, and forward the request to another application.
Ivan Jouikov
Ranch Hand

Joined: Jul 22, 2003
Posts: 269
thank thee!
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 861
I'm not sure what the j2ee spec says, but my experience is that static variables in server scope are shared by all applications. For example a static variable in the a jar in the servers class path.


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sharing variable across applications?