我正在开发一个Web应用程序使用jsp
和servlet
。在我的应用程序有一个注销部分,在我使用下面的代码:会议未注销清除
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);
}
}
}
在浏览器中,如果我们连续使用,每周想不清除历史,那么如果我们登录并点击注销,它将注销重定向到主页,但会话仍然存在。 会话在注销时未被清除。
发生了什么问题?我的代码中是否还需要其他更改?
我觉得在这一行有一些问题HttpSession ss = rq.getSession(false);正如上面提到的代码! – Santhucool
你有没有例外? – Niranjan
NOPE !!我没有得到任何 – Santhucool