录功能经常有保留密码xx天的功能,这可以设置Cookie的有效时间,但是如果我不选择保留密码,在退出网站
就得马上清空cookie,怎么实现呢?
解决方案1:
cookie.setMaxAge(0);cookie.setPath(path);response.addCookie(cookie);
详细参考方案2:
<%@ page contentType="text/html; charset=GBK" language="java"%>
<%
String[] cookiename = {"JSESSIONID","SECURE_AUTH_ROOT_COOKIE","SECURITY_AUTHENTICATION_COOKIE"};
for(int index = 0, len = cookiename.length; index < len; index ++) {
javax.servlet.http.Cookie c = new javax.servlet.http.Cookie( cookiename[index], null);
c.setMaxAge(0);
c.setPath("/");
response.addCookie(c);
javax.servlet.http.Cookie c2 = new javax.servlet.http.Cookie( cookiename[index], null);
c2.setMaxAge(0);
c2.setPath(request.getContextPath());
response.addCookie(c2);
}
//System.out.println("clear cookie LtpaToken");
%>