3

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?

javanna
  • 59,145
  • 14
  • 144
  • 125
Vítor Nóbrega
  • 1,219
  • 4
  • 26
  • 53

1 Answers1

3

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

Community
  • 1
  • 1
Aravind A
  • 9,507
  • 4
  • 36
  • 45