Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 827
Vítor Nóbrega Avatar asked Jun 30 '26 09:06

Vítor Nóbrega


1 Answers

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

like image 137
Aravind A Avatar answered Jul 03 '26 06:07

Aravind A