Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 注销后,不要返回到jsp中的上一页_Javascript_Jsp - Fatal编程技术网

Javascript 注销后,不要返回到jsp中的上一页

Javascript 注销后,不要返回到jsp中的上一页,javascript,jsp,Javascript,Jsp,为了防止用户在注销后返回,我在home.jsp页面中使用了以下代码 <% if (session.getAttribute("authe") != null && session.getAttribute("authe").equals(true)) { } else { response.sendRedirect("login.jsp"); } %> 我在logout.jsp中使会话无效 它工作得很好,但当我在注销后按下后退按钮时,它仍然会进入

为了防止用户在注销后返回,我在
home.jsp
页面中使用了以下代码

<% 
if (session.getAttribute("authe") != null && session.getAttribute("authe").equals(true)) {

}
else {  
    response.sendRedirect("login.jsp");
}
%>

我在
logout.jsp
中使会话无效

它工作得很好,但当我在注销后按下后退按钮时,它仍然会进入主页,但在重新加载主页后,它会移动到登录页面。 我认为这是由于浏览器的默认操作


如何使其有效地工作?

home.jsp
中,将标题设置为
无缓存

<%
   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);
 %>

您可以使用:

<%
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);
}
%>


你排除缓存了吗?这对我不起作用,但@Deepak Singh answer有效。