File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes sendRedirect and Session attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "sendRedirect and Session attributes" Watch "sendRedirect and Session attributes" New topic

sendRedirect and Session attributes

Abhishek Asthana
Ranch Hand

Joined: Sep 08, 2004
Posts: 146
I wanted to know if response.sendRedirect function passes the session attributes set in the sender servlet to the called servlet?

Dharmanand Singh

Joined: Oct 27, 2004
Posts: 13
If I got you right, you are asking if the session attributes can be accessed after you have redirected the response. As per my knowledge, only the request object dies after response redirecting (and a new request object initiated). Session object is related to the user session and attributes in the session object will not die until the session expires or you explicitly remove that attribute. Hence compiling all these, the session attributes can be accessed after setting them even after redirecting the response.
[ April 07, 2005: Message edited by: Dharmanand Singh ]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

It doesn't pass anything.
It just tells the browser to make a new request with the given address.
The new request will have access to the session variables because they are "session" scoped.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: sendRedirect and Session attributes
It's not a secret anymore!