【发布时间】:2015-07-22 06:54:03
【问题描述】:
我正在使用jsp 和servlet 开发一个Web 应用程序。在我的应用程序中,我有一个注销部分,我在其中使用以下代码:
public class logout extends HttpServlet {
public void service(HttpServletRequest rq, HttpServletResponse rs) throws IOException, ServletException {
try {
HttpSession ss = rq.getSession(false);
if (ss.getAttribute("uid") == null) {
rs.sendRedirect("/");
}
rs.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
rs.addHeader("Cache-Control", "post-check=0, pre-check=0");
rs.setHeader("Pragma", "no-cache");
rs.setDateHeader("Expires", 0);
HttpSession session = rq.getSession(false);
session.setAttribute("uid", null);
session.invalidate();
rs.sendRedirect("/");
} catch (Exception exp) {
// rs.sendRedirect("/");
RequestDispatcher dd = rq.getRequestDispatcher("/");
dd.forward(rq, rs);
}
}
}
在浏览器中,如果我们连续使用并假设一周没有清除历史记录,那么如果我们登录并单击注销,则会将注销重定向到主页但会话仍然存在。 退出时会话未清除。
这个问题是怎么回事?我的代码还需要更改吗?
【问题讨论】: