You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by JB JUNG <it...@samsung.com> on 2012/11/26 04:56:44 UTC

session sharing in Tomcat v7.0

Hi,

When I created 2 webapps in 1 host and I wanted to get these 2 webapps to
use 1 session.

Accordingly, I configured my server.xml like this.

 

<Host appBase="webapps" autoDeploy="true" name="localhost"
unpackWARs="true">

           <Context path=”/app1” sessionCookiePath=”/” ></Context>

           <Context path=”/app2” sessionCookiePath=”/” ></Context>

</Host>

 

Then, I made simple Servlet in each webapp.

Here are doget methods for each Servlet.

 

Servlet 1 in app1

request.getSession().setAttribute(“data”,”111”);

 

Servlet 2 in app2

request.getSession().getAttribute(“data”);

 

But I failed to get data from session in app2, it always returned null.

Finally, I started my tomcat in debug mode and checked each session object.

 

one session was 

StandardSession[3A359FF7CCC02303335DA09EDD569F0A]

org.apache.catalina.session.StandardSessionFacade@2d517aa8

and it had some attributes.

 

another was

StandardSession[3A359FF7CCC02303335DA09EDD569F0A] <<<<same session ID!!??

org.apache.catalina.session.StandardSessionFacade@3e322634 <<< but not
façade… LOL

and it had no attributes.

 

In spite of same session ID, but why this situation happened?

and how can I get these two webapps to share session?

Thanks J


Re: session sharing in Tomcat v7.0

Posted by Mark Thomas <ma...@apache.org>.
JB JUNG <it...@samsung.com> wrote:

>and how can I get these two webapps to share session?

You can't with Tomcat configuration. You'd need to use some external component to share data between the applications (e.g. database, cache, etc.)

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: session sharing in Tomcat v7.0

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: JB JUNG [mailto:itsjb.jung@samsung.com] 
> Subject: session sharing in Tomcat v7.0

> When I created 2 webapps in 1 host and I wanted to get these 2 webapps 
> to use 1 session.

This is specifically prohibited by the servlet spec (which you should read):

"7.3 Session Scope

"HttpSession objects must be scoped at the application (or servlet context) level. 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."

You need to provide your own mechanism to keep track of common data, outside of the session object.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org