• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sharing session across servlet context

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to share the same session between 2 or more webapps. I was wondering if anyone could help me on this.
Thanks,
Srini
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
well, at first sight it looks like "Single Sign On" Mechanism to me which i would not go in details as thats not a subject of this forum.
if i restrict myself to Java Servlets then...
initally i thought we can just pass Session object to another appplication. for this there r two scenarios,
1. if we are invoking one app from another then we can probably pass Session object as an argument/parameter and thus share it.
2. if we can serialize the session object then we can share it by putting it in WEB-INF dir and get it by getResource() or sth like that.
i 'm not sure about how the first option will work, if it can work as if we are only talking about servlets then we cant really pass Object as a parameter. i have never tried creating object of a servlet in another servlet but i assume thats not possible, otherwise what we can do is- we can call a method on another servlet and pass the session object as an argument and do the stuff...
there is a problem here in 2nd case. as we aren't really SHARING the same object. so if the original app changes the session object's content we can't reflect that in the other app to which we passed the session object's reference. again i guess there is something we can do like Version control stuff to let other app have latest version of the serialized object(tho i forgot how exactly it was working).
waiting for experts comments...
regards
maulin.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think we dont need to pass session between the apps on the same server because session is created first time around and later on we just need to manage the same among all the web apps.
You need to be careful about the objects you are storing in the session with same "keys" when you want to share session among multiple apps.

You dont have to code anything fancy other than taking the above care to share the session.
But managing session in multiple servlet contexts is difficult. Either you need to serialize sessions or store in db but there is always a possibility of single point of failure. I have never dealt with the issue.
You can create two apps with one servlet in each.
Try the above code and I'm sure it works.

Waiting for more postings....

-Srini
 
Srini Admala
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Try the above code and I'm sure it works


I mean try something similar and I'm sure it works.
I'll try to get back with some code.......
-Srini
 
reply
    Bookmark Topic Watch Topic
  • New Topic