【发布时间】:2019-06-23 16:11:52
【问题描述】:
当我访问我的页面.../index.jsp 而没有HttpSessions 时,index.jsp 仍然会创建JSESSIONID-cookie。更糟糕的是,在负责注销人员的 servlet 中,session.invalidate() 似乎无法解决问题。
index.jsp 看起来像这样:
<%@page import="javax.servlet.http.Cookie"%>
<%@page contentType="text/html" pageEncoding="utf-8"%>
<%@page session="true"%>
<%!
void removeJSessionIdCookie(HttpServletResponse response) {
Cookie cookie = new Cookie("JESSIONID", "");
cookie.setValue(null);
cookie.setMaxAge(0);
cookie.setPath("/");
response.addCookie(cookie);
}
%>
<%
if (session != null) {
out.print("Session not null.");
if (session.getAttribute(Config.CURRENT_USER_ATTRIBUTE) != null) {
out.print("have user");
request.getRequestDispatcher("app.jsp").forward(request, response);
return;
} else {
out.println("no user here");
session.invalidate();
removeJSessionIdCookie(response);
}
}
%>
<html>...</html>
【问题讨论】: