0

下面的代码是我的 servlet。我使用了doFilter()缓存控制和doPost()使会话无效并重定向到登录页面。后退按钮问题仍然存在。有人能告诉我我做错了什么吗?请在您投反对票之前告诉我原因!提前致谢。

 public class LogoutServlet extends HttpServlet implements Servlet, Filter{

 @Override
  public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)   throws IOException, ServletException {

       HttpServletResponse hsr = (HttpServletResponse) res;
       hsr.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
       hsr.setHeader("Pragma", "no-cache"); // HTTP 1.0.
       hsr.setDateHeader("Expires", 0); // Proxies.
      chain.doFilter(req, res);
   }

 @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

   }


 @Override
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {


          HttpSession session = request.getSession(false); 
            session.invalidate();
            response.sendRedirect("login.jsp");

  }

  @Override
  public void init(FilterConfig filterConfig) throws ServletException {
      throw new UnsupportedOperationException("Not supported yet.");
  }
}
4

0 回答 0