• 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

request dispatcher

 
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I have a question. Form my servlet i am dispatching the request to another web application . Now the problem is if i set anything in the session object and then dispatch to another servlet in another web application i am not able to get values form the session that i had set previously.

I my second servlet i am using req.getSession(false) that means i am getting the same session object. Don't understand why the values from the session object is cleared. Am I doing something wrong.

Thanks in advance.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. This is the right behavior indeed, because both applications are different. You can't share the session between two different apps. You can share that via DB or some file.

cheers.
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
Thanks for the reply. But i am not able to understand one thing. How this session object is associated with the web application. If my browser is sending the cookie having the session id and from my servlet i am forwarding the same request to a different web application then the server should return the same session object.

Indeed in my case the server is returning the same session object because in my second servlet i am using getSession(false) and the session id's are same. That means before the server is making the session object available in second servlet its clearing all the values. Is this what specs say. may be i will look into the spec.

Thanks for your reply.

Sawan
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have heard that in websphere you can do it. There is this file sessionshare.xml. But as specs prohibits it its a non-J2EE way.

Thanks.

Sawan
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just because the session IDs are the same that doesn't mean they share the same session.

In fact I'd consider it highly suspicious that the session IDs are the same.
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am able to get the session object using req.getSession(false)

Thanks
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, but you aren't getting the same sesssion object.
You can't share session inforamtion accross webapps


SRV.7.3 Session Scope
objects must be scoped at the application (or servlet context) level.
HttpSession
The underlying mechanism, such as the cookie used to establish the session, can be the same for different contexts, but the object referenced, including the attributes in
that object, must never be shared between contexts by the container.
To illustrate this requirement with an example: if a servlet uses the
RequestDispatcher to call a servlet in another Web application, any sessions
created for and visible to the servlet being called must be different from those
visible to the calling servlet.


[ January 28, 2005: Message edited by: Ben Souther ]
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i read that in specs. . The only thing that confused me was that how in the second servlet req.getSession(false) is returning the session object. Anyways. Thank you all for your replies.


sawan
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it returs its own session object, not the one from the other server
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thnaks Jeroen
reply
    Bookmark Topic Watch Topic
  • New Topic