java 按下提交按钮后java jsp清除会话
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10289273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java jsp clear session after press submit button
提问by FrankSharp
This my code
这是我的代码
if(request.getParameter("btnlogOut") != null)
{
session.invalidate();
}
Its not clear the session....
它不清楚会话....
Thanks
谢谢
Frank
坦率
回答by BalusC
It does.
确实如此。
Most likely you're sending a forward instead of a redirect to the result page. This way the old session variables are still accessible in EL scope. Make sure that you're sending a redirect after the invalidate.
很可能您发送的是转发而不是重定向到结果页面。这样,旧的会话变量仍然可以在 EL 范围内访问。确保您在失效后发送重定向。
session.invalidate();
response.sendRedirect(request.getContextPath() + "/index.jsp");
This way the browser will be instructed to send a brand new HTTP request on the given URL without the session cookie and hence the associated servlet request-response will get a brand new HttpSession
object instance.
这样,浏览器将被指示在给定的 URL 上发送一个全新的 HTTP 请求而没有会话 cookie,因此关联的 servlet 请求-响应将获得一个全新的HttpSession
对象实例。