This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Using default ServletContext? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Using default ServletContext?" Watch "Using default ServletContext?" New topic

Using default ServletContext?

Neil Laurance
Ranch Hand

Joined: Jul 18, 2002
Posts: 183
A quick question for all you Servlet API gurus :-)
I have some information that I need to store past the end of an HttpSession lifecyle.
This information needs to be available to all servlets in the web application.
Regarding the ServletContext, the Servlet Specification states:

SRV.3.2 Scope of a ServletContext Interface
There is one instance object of the ServletContext interface associated with each
web application deployed into a container. In cases where the container is
distributed over many virtual machines, a web application will have an instance of
the ServletContext for each VM.
Servlets in a container that were not deployed as part of a web application are
implicitly part of a �default� web application and have a default ServletContext.
In a distributed container, the default ServletContext is non-distributable and
must only exist in one VM.

Therefore, this information cannot be stored in the web application's ServletContext. However, we are using tomcat, which can be configured to allow access to the default context with the following entry in the server.xml configuration file:

This default context is guaranteed to be in a single JVM only, so perhaps we can store stuff in there. Glorious hack, or dangerous approach?
For example, the following JSPs can share information between web applications, so I am guessing this approach should work for distributed web applications also:
File 1:

File 2:

Comments please :-)
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60785

Therefore, this information cannot be stored in the web application's ServletContext.

Why do you think this? You haven't described anything about your setup that precludes using the web app's servlet context.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Consider Paul's rocket mass heater.
subject: Using default ServletContext?
Similar Threads
ServletContext Confusion...
Servlet context
question on distributed application
ServletContext in distributable web application
Distributed applications