tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bernhard Slominski <>
Subject AW: cross context info
Date Wed, 14 Sep 2005 11:09:36 GMT
Hi Alain, 

First of all the session is ALWAYS on application scope, this is not an
Tomcat specific behaviour but a requirement of the Specification:
"SRV.7.3 Session Scope
HttpSession objects must be scoped at the application (or servlet context)
The underlying mechanism, such as the cookie used to establish the session,
can be
the same for different contexts, but the object referenced, including the
attributes in
that object, must never be shared between contexts by the container."

So there is no way around this, if the sessions were replicated across the
applications it would violate the specification.

When you enable crossConext for your application:
<Context crossContext="true" docBase="testapp" path="/testapp"

you can get the context for another application:
ServletContext context2 = context.getContext("/testapp");

and set attributes:
context2.setAttribute("test","JSP is great!");

But you cannot get to the session in the other application.

So what you can do is implement the session swapping on your own (Cookies,
via the Database) or merge your applications into one.

Some links from the Sun Forums:

Cheers Bernhard

> -----Urspr√ľngliche Nachricht-----
> Von: Alain Gaeremynck []
> Gesendet: Mittwoch, 14. September 2005 03:03
> An: Tomcat Users List
> Betreff: cross context info
> I have 2 webapps living on the same server and they are linked to the 
> same user experiance..  Now both apps require login but i 
> don't want my 
> users to have to login on both apps.  Also while they are browsing in 
> one context i don't want the session to expire for the other context. 
> so the question is  Is there a way to do session.setAtribute in one 
> context and retrieve it from another and also to link the 2 
> session so 
> that they don't expire or expire at the same time? 
> i'd like not to have to use hidden iframe and stuff like that
> thanks!
> -- 
> Alain Gaeremynck
> CTO Le Groupe Interstructure
> (514) 374-1110
> (514) 825-7810 cell
> weblog:
> (En informatique, comme en musique, n'importe quoi sauf du commercial)
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message