最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - after logout do not go back to previous page in jsp - Stack Overflow

programmeradmin2浏览0评论

To prevent user to go back after logout i used following code in home.jsp page

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

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

and I invalidated the session in 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?

To prevent user to go back after logout i used following code in home.jsp page

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

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

and I invalidated the session in 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?

Share Improve this question edited Jul 30, 2017 at 8:30 xlm 7,64415 gold badges58 silver badges60 bronze badges asked Oct 13, 2013 at 16:50 manchumanchu 551 gold badge2 silver badges7 bronze badges 1
  • Have you ruled out caching? – Brandon Commented Oct 13, 2013 at 17:01
Add a ment  | 

2 Answers 2

Reset to default 6

In home.jsp put header as 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);
 %>

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);
}
%>
发布评论

评论列表(0)

  1. 暂无评论