我在删除Cookie时遇到问题
MemberArea.jsp
<%
Cookie[] cookies = request.getCookies();
if(cookies != null)
{
for(Cookie cookie: cookies)
{
if(cookie.getName().equals("username"))
username = cookie.getValue();
else if(cookie.getName().equals("JSESSIONID"))
sessionID = cookie.getValue();
}
}
if(username == null || sessionID == null)
response.sendRedirect("login.jsp");
%>
Username: <%=username %> <br>
Current Session: <%=sessionID %>
<form action="<%= request.getContextPath() %>/MemberAreaController"
method="get">
<input type="hidden" name="action" value="destroy">
<input type="Submit" value="Logout">
</form>
</body>
下面的代码(MemberController.java)是从MemberArea.jsp触发的
request.getSession().invalidate();
Cookie[] cookies = request.getCookies();
System.out.println(cookies);
for(Cookie cookie: cookies)
{
System.out.println(cookie.getName());
System.out.println(cookie.getValue());
cookie.setValue(null);
cookie.setMaxAge(0);
cookie.setPath("/");
response.addCookie(cookie);
}
response.sendRedirect("login.jsp");
单击注销按钮并返回MemberArea.jsp后,用户仍将登录。