简体   繁体   English

如何防止用户在退出系统后导航回 JSP 页面?

[英]How to prevent user navigate back to a JSP page after logout from the system?

Currently, I had invalidated session on the logout page and also clear the cache in the Main Menu.目前,我在注销页面上使会话无效,并清除了主菜单中的缓存。 But it displays the HTTP Status 500 - Internal Server Error when I click the Back button.但是当我单击“后退”按钮时,它会显示 HTTP 状态 500 - 内部服务器错误。

How to keep displaying the login page since the session is invalidated instead of this error?由于会话无效而不是此错误,如何继续显示登录页面?

Mainmene.jsp
<%
    response.setHeader("Cache-Control","no-cache");
    response.setHeader("Cache-Control","no-store");
    response.setHeader("Pragma","no-cache");
    response.setDateHeader ("Expires", 0);

    if(session.getAttribute("email")==null) {
        response.sendRedirect("loginpage.jsp"); // GO TO LOGIN PAGE
        }
    %>


Logout.java
    protected void doPost(HttpServletRequest request, HttpServletResponse 
response)
        throws ServletException, IOException {

        response.setContentType("text/html");

        HttpSession session=request.getSession();  
        session.invalidate(); 

        response.sendRedirect("loginpage.jsp");

}

You can use a Filter that checks if there is a user object in the sessionScope and apply it to a given type of url-patterns .您可以使用Filter来检查 sessionScope 中是否存在用户对象并将其应用于给定类型的url-patterns You can check here to see how to use.您可以在这里查看如何使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM