| Author |
request dispatcher
|
sawan parihar
Ranch Hand
Joined: Aug 24, 2004
Posts: 250
|
|
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.
|
Sawan<br />SCJP,SCWCD,SCBCD<br /> <br />Every exit is an entry somewhere.
|
 |
Adeel Ansari
Ranch Hand
Joined: Aug 15, 2004
Posts: 2874
|
|
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
Joined: Aug 24, 2004
Posts: 250
|
|
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
Joined: Aug 24, 2004
Posts: 250
|
|
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
Joined: Oct 12, 2000
Posts: 5093
|
|
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.
|
42
|
 |
sawan parihar
Ranch Hand
Joined: Aug 24, 2004
Posts: 250
|
|
I am able to get the session object using req.getSession(false) Thanks
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
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 ]
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
sawan parihar
Ranch Hand
Joined: Aug 24, 2004
Posts: 250
|
|
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
Joined: Oct 12, 2000
Posts: 5093
|
|
it returs its own session object, not the one from the other server
|
 |
sawan parihar
Ranch Hand
Joined: Aug 24, 2004
Posts: 250
|
|
|
Thnaks Jeroen
|
 |
 |
|
|
subject: request dispatcher
|
|
|