On Thu, 29 Mar 2001, Andy Mauro wrote:

> Hey all.
> 
> Background:
> We are packaging our apps as a collection of functional modules. For example
> a shopping cart app would be packaged as multiple Servlet2.2 WAR (web
> application
> archive) files that would then be deployed in a servlet container. Each
> webapp (e.g. cart, store, checkout) would be deployed in its own servlet
> context. They have logic that lets them work alone as a standalone module or
> together as a cohesive application.
> 
> We decided to use the Servlet session tracking mechanism to store data that
> is shared between modules
> 
> One example of key/value data that would be stored in the session is:
> subscriber=true.
> 
> We are running into trouble though. I have noticed that different contexts
> (in Tomcat 3.2.1) create different sessions ids. This means that if I login
> and set session.setAttribute("subscriber", "true") in the /entrylogic
> context, and then goto (in the same call) the /checkout context and attempt
> to
> retrieve session.getAttribute("subscriber"), the getAttribute will return
> null because the sessions (ids) are different.
> 
> Does anyone know of a way to share sessions between contexts (or the
> equivalent)? Can someone explain this behaviour?
> 

You are trying to accomplish something that is expressly prohibited by the
servlet specification.  Sessions and their attributes are not visible
across web applications, even if they are running in the same machine.

If your application components need to share information, there are
basically three choices:

* Run them inside the same web application

* Use external mechanisms like databases, EJBs, etc. to share info

* (Not guaranteed to be portable) use classes that are loaded from
  the shared classloader (i.e. the $TOMCAT_HOME/lib directory for Tomcat),
  which are visible across webapps.

> Thanks in advance,
> -Andy
> 
> 

Craig McClanahan


Reply via email to