录功能经常有保留密码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");
%>
-
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载,整理或搜集自网络.欢迎任何形式的转载,转载请注明出处.
转载请注明:文章转载自:[169IT-IT技术资讯]
本文标题:JSP中清空cookie代码参考