Todd wrote:

> Is there a way to share sessions across webapps running in the same 
> container? 

Yes, I do this for a set of apps which I wrote recently.

You need to make sure each of the apps which need access to the
cross-context session are defined like this in server.xml:

<Context path="/mycontext" docBase="mydocbase" debug="0" reloadable="true"
crossContext="true">
...
</Context>

crossContext="true" is the important bit.

If you're deploying your apps as WARs you'll need to deploy them, restart
Tomcat, edit server.xml and then restart Tomcat again...!

As for accessing this shared session, I found some code on the web ages ago
which had examples but I can't find this at the moment.

The code I use for reading information from the shared session looks like
this:

ServletContext currentContext = config.getServletContext();
ServletContext sharedSessionContext =
currentContext.getContext("sharedcontextname");
Hashtable sessiondata =
(Hashtable)sharedSessionContext.getAttribute("attributename");

However, as others have suggested, I was only able to get code like this
working when loaded from common/lib or common/classes.  

In my case, I have this code running in a servlet filter loaded from a JAR
in common/lib.

Hope that helps.


Robbie

Reply via email to