如何删除 Javaservlet 中的 cookie?
我试过了: Http://www.jguru.com/faq/view.jsp?eid=42225
编辑: 以下方法现在已经成功运行,看起来是以下方法的结合:
response.setContentType("text/html");
还有
cookie.setMaxAge(0);
在我做:
//remove single signon cookie if it hasn't been validated yet
response.setContentType("text/html");
Cookie cookie = new Cookie(SSORealm.SSO_COOKIE_NAME, "");
cookie.setDomain(SSORealm.SSO_DOMAIN);
cookie.setMaxAge(-1);
cookie.setPath("/");
cookie.setComment("EXPIRING COOKIE at " + System.currentTimeMillis());
response.addCookie(cookie);
根据 文件,当浏览器关闭时,它将使 Cookie 过期。
负值意味着 Cookie 不会持久存储,并且在 Web 浏览器退出时将被删除。如果值为零,则会删除 Cookie。
使 cookie 过期的完整工作代码片段是:
//remove single signon cookie if it hasn't been validated yet
response.setContentType("text/html");
Cookie cookie = new Cookie(SSORealm.SSO_COOKIE_NAME, "");
cookie.setDomain(SSORealm.SSO_DOMAIN);
cookie.setMaxAge(0);
cookie.setPath("/");
cookie.setComment("EXPIRING COOKIE at " + System.currentTimeMillis());
response.addCookie(cookie);