This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Servlets and the fly likes Sharing Session across ServletContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Sharing Session across ServletContext " Watch "Sharing Session across ServletContext " New topic
Author

Sharing Session across ServletContext

srinivasan ganesan
Ranch Hand

Joined: Mar 09, 2001
Posts: 54
I have a situation where I want to share the session between 2 or more webapps. I would appreciate any help on this.
Thanks,
Srini
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
As you have found out, the whole purpose of Sun's servlet API is to keep web apps totally separate so you will have to go outside the servlet API to do this. There are plenty of options, for instance a separate database, RMI, etc.
Bill
srinivasan ganesan
Ranch Hand

Joined: Mar 09, 2001
Posts: 54
Bill,
Is there a reason why you shouldn't be able to do that? I couldnt come up with one. BTW all my applications reside in the same server. I appreciate your help on this.
Thanks,
Srini
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi srinivasan,
i tried to explore possibilities to do that in the SCWCD forum. have a look at that.
regards
maulin.
Paul Chen
Greenhorn

Joined: Feb 09, 2002
Posts: 8
Suppose to create one class and use singleton pattern to create only one instance in one init() of servlets, we can use this instance to share data between multi web apps.
Am I missing something?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
Creating a class shared by both applications only works if both use the same ClassLoader - I don't think you can rely on it.
As I said, Sun's design requires "Web Applications" to be completely separate and independent. The reason being they want to encourage the sale of web applications and interactions between web applications would cause endless debugging problems.
The solution is to run an entirely separate application that any web application servlet can talk to and share data. This is easily done - you have several options. Chapter 9 in my servlets & JSP book works out an example using a Chat server as an example.
Bill
 
GeeCON Prague 2014
 
subject: Sharing Session across ServletContext