Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSP Redirect: Session Loss Issues

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?

like image 552
Humphrey Bogart Avatar asked Jan 25 '26 22:01

Humphrey Bogart


1 Answers

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.

like image 144
Ronald Wildenberg Avatar answered Jan 29 '26 13:01

Ronald Wildenberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!