*
The moose likes Servlets and the fly likes Sharing Session between Two WAR Files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Sharing Session between Two WAR Files" Watch "Sharing Session between Two WAR Files" New topic
Author

Sharing Session between Two WAR Files

Ola Daniel
Ranch Hand

Joined: Jul 27, 2005
Posts: 105
I need to share some session objects between two war files on the same server. How can I get this done??? I have two war files service.war and retiree.war, You log into the Application from service.war, and set some session atributes such as the DBname, type, userid and a host of other attributes. All my JSPs and servlets in the retiree.war need this attributes. I am having trouble sharing the same session between both apps. Help please! By the way I am using a JBoss server.


SCJP 1.4, SCWCD 1.4
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler et al, Refactoring: Improving the Design of Existing Code, 1999
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


How can I get this done???

You can't. Session information is scoped to the current ServletContext, and there is one ServletContext per web app. ServletContext information is not designed to be shared.

One question which jumps out is if you have stuff in the session needed by both web apps, why do you have two web apps at all? Couldn't you combine them into one?

If you can't, you could just pass this info with the request.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ola Daniel
Ranch Hand

Joined: Jul 27, 2005
Posts: 105
Paul Sturrock if it is not possible to share the same session across both webapps, is there a way I can make the retiree.war a module of service.war without having to put the content of retiree.war into the main application service.war?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

No there is no parent child relationship between webapps.

Why did you make them two separate webapps?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ola Daniel
Ranch Hand

Joined: Jul 27, 2005
Posts: 105
What I am trying to accomplish is to have a web application that manages human resources in service.war and then have an optional package retiree.war that would only be distributed on request as a plus. I guess I will have to resort to just placing the contents of retiree.war in a separate folder inside service.war...

service.war
- /WEB-INF
- /retiree

Instead of
service.war & retiree.war, side by side.
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

What kind of session objects you'd like to share? If it's just logged user credentials, then you can use single sign on approach. You can also pass data using HTML form hidden object, HTTP cookies and some other technique. If you know upfront servlet container where your apps will run on, then you can use some servlet container undocumented capabilities to share session objects.


Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sharing Session between Two WAR Files