本文介绍了无法删除的cookie JSESSIONID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了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?

推荐答案

尝试设置内容类型和域按如下说明的。你还卖乖尝试使用过期解释的SessionRegistry 这里

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 20:00