I had a problem like this when the cookie saved the value even after setting the maximum age to 0 and the value to "".
I used firefox to look at cookie attributes to help debug. Upon login, the servlet called my cookie class sets a cookie, and the path to the cookie is "/ javawork /". When logging out, the JSP page called the same cookie class โdeletingโ the cookie, setting the maximum age to 0. But the JSP page was in a subfolder of the web application, so when I created the cookie of the same name with the maximum age of 0, it created a new cookie with the path / javawork / test _login / ".
So, the โnewโ cookie immediately expired, but the original one still existed. In my delete cookie function, I needed to set the path of the โnewโ cookie to โ/ javawork /โ, and when I set the maximum age to 0 and added it, it updated the original cookie and allowed me to log out correctly.
I hope this helps.
source share