JSP重定向:会话丢失问题 [英] JSP Redirect: Session Loss Issues

查看:710
本文介绍了JSP重定向:会话丢失问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 response.sendRedirect(URL)替换了< jsp:forward page =URL> code>,我发现我知道丢失会话一旦重定向发生。有没有办法保留会话与重定向,或重新构建会话cookie并与重定向一起发送?

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?

我知道我可以使用JavaScript通过<$

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

任何帮助?

推荐答案

您不应该重新发送cookie,因为如果您建立了会话,cookie应该已经在客户端(浏览器)。

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?

浏览器是否接受Cookie?否则你应该使用url重写。这是最有可能的原因。您可以尝试使用 HttpServletResponse.encodeRedirectURL ,然后将网址传递给 response.sendRedirect

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.

这篇关于JSP重定向:会话丢失问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆