当前位置: 动力学知识库 > 问答 > 编程问答 >

spring - Can't remove JSESSIONID cookie

问题描述:

I am using a Spring controller with a HttpServletRequest and response to remove cookies.

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);

}

}

After this execution, all cookies with the name JSESSIONID should be removed.

What is my mistake?

网友答案:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: