javascript 注销后不要回到jsp中的上一页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19347700/
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
after logout do not go back to previous page in jsp
提问by manchu
To prevent user to go back after logout i used following code in home.jsp
page
为了防止用户在注销后返回,我在home.jsp
页面中使用了以下代码
<%
if (session.getAttribute("authe") != null && session.getAttribute("authe").equals(true)) {
}
else {
response.sendRedirect("login.jsp");
}
%>
and I invalidated the session in logout.jsp
.
我使logout.jsp
.
It worked fine but when I pressed back button after logout it still goes to home page but after reloading that home page it moves to the login page. I thought it it due to the browser default action.
它工作正常,但是当我在注销后按下后退按钮时,它仍会转到主页,但在重新加载该主页后,它会移动到登录页面。我认为这是由于浏览器的默认操作。
How to make it to work effectively?
如何让它有效地工作?
回答by Harika Choudary Kanikanti
In home.jsp
put header as no-cache
:
在home.jsp
放标题为no-cache
:
<%
response.addHeader("Cache-Control", "no-cache,no-store,private,must-revalidate,max-stale=0,post-check=0,pre-check=0");
response.addHeader("Pragma", "no-cache");
response.addDateHeader ("Expires", 0);
%>
回答by Deepak Singh
You can use:
您可以使用:
<%
try {
response.setHeader("Cache-Control","no-cache");
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
if (session.getAttribute("userid")==null) {
response.sendRediredirect("login.jsp");
}
else {}
}
catch(Exception ex) {
out.println(ex);
}
%>