• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request dispatcher

 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • 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.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I am able to get the session object using req.getSession(false)

Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Thnaks Jeroen
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic