views:

831

answers:

1

Having replaced a <jsp:forward page="URL"> with a response.sendRedirect("URL");, I find I know lose the session once the redirect occurs. Is there a way to preserve the session with a redirect, or to reconstitute the session cookie and send it along with the redirect?

I know I could use JavaScript via window.location = "URL";, but that is far from ideal!

Any help?

+2  A: 

You should not have to resend the cookie, because if you had a session established, the cookie should already be on the client (the browser).

Are you sure you lose the session? How do you detect this? Do you have a new session in the page represented by the url you redirect to?

Does the browser accept cookies? Otherwise you should use url rewriting. This is the most probable cause. You could try use HttpServletResponse.encodeRedirectURL before passing the url to response.sendRedirect.

Ronald Wildenberg
Betweeen the pages I share, as a session attribute, the user's name. When I simply forward the page, it is displayed as normal, but when I redirect, I get "null" as the name... Using the shopping cart works, however, so I know a new session is established; I shall try your recommendation and see if my problems are solved!
Beau Martínez
And, did it work?
Ronald Wildenberg