File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Session variables across domains Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session variables across domains" Watch "Session variables across domains" New topic

Session variables across domains

Mike Cronin

Joined: Apr 17, 2002
Posts: 25
Hi there,
I have a servlet in one domain that sets a session variable and displays a link to a servlet in another domain. When the client clicks on the link, I'd like to validate the session variable set in the initiating domain.
Is it possible to retrieve session variables across domains?
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
i'm not sure what your asking but if you have multiple sites on the same server you can use application level variables between them

Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
if you have multiple sites on the same server you can use application level variables between them
Hmm. I think this is unlikely. "different sites on the same server" are almost always implemented as either separate servlet containers attached to a "front door" web server such as apache, or as separate web applications in a single container. Both of these cases will not allow the sharing of application- or sesion- level information.
To share anything between separate web applications you usually need to either store the information somewhere that both applications can read from (a database, JNDI, a file etc.), or use a network-based protocol (FTP, HTTP, web services, RMI, ...) to transfer it directly from one application to another.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Kyle Brown
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
OK, what you're referring to is a limitation set in the Servlet Spec that Session scope is limited to an individual web app. Actually, some Application Server vendors (such as WebSphere) provide special configuration switches that relax this constraint, but if you use them, you are now no longer writing a portable application. If that's not a concern to you, and you're using a server with that capability, more power to you.
On the other hand, to write something like this in a J2EE-compliant way, I'd suggest you store the "shared" information in something like a shared database, perhaps keyed by a value placed in a cookie.
[ January 01, 2004: Message edited by: Kyle Brown ]

Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at for other WebSphere information.
Mike Cronin

Joined: Apr 17, 2002
Posts: 25
Hey gang,
Thanks for all that input.
As of today, I decided to move the apps under the same domain which of course solved this issue all together.
Thanks again for your assistance!
I agree. Here's the link:
subject: Session variables across domains
It's not a secret anymore!