无法删除的cookie JSESSIONID [英] Can't remove JSESSIONID cookie
问题描述
我使用了HttpServletRequest和响应一个Spring控制器删除的cookie。
I am using a Spring controller with a HttpServletRequest and response to remove cookies.
当我需要删除cookie的,我有这样的code:
When I need to remove the cookie, I have this code:
Cookie[] allCookies = request.getCookies();
for (int i = 0; i < allCookies.length; i++)
{
String name = allCookies[i].getName();
if (name.equalsIgnoreCase("JSESSIONID"))
{
logger.info(i + " Name=" + name + " Value=" + allCookies[i].getValue());
cookieToDelete = allCookies[i];
cookieToDelete.setValue("");
cookieToDelete.setMaxAge(0);
cookieToDelete.setVersion(0);
cookieToDelete.setPath("/");
response.addCookie(cookieToDelete);
}
}
这个执行后,一个名为JSESSIONID所有的cookies应该被删除。
什么是我的错?
After this execution, all cookies with the name JSESSIONID should be removed. What is my mistake?
推荐答案
尝试设置内容类型和域按如下说明的如何删除一个Cookie在Java Servlet的。你还卖乖尝试使用过期解释的SessionRegistry <一个会话href=\"http://static.springsource.org/spring-security/site/docs/3.1.x/reference/session-mgmt.html#list-authenticated-principals\"相对=nofollow>这里
Try setting the content type and domain as explained here How do you remove a Cookie in a Java Servlet .You cold also try expiring the session using SessionRegistry explained here
这篇关于无法删除的cookie JSESSIONID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!