Every time a different page is requested, I do the following:
Cookie cookie = new Cookie("c1", someString); // can be {a, b, c}, for example
cookie.setMaxAge(31556926);
response.addCookie(cookie);
cookie = new Cookie("c2", Integer.toString(someInt));
cookie.setMaxAge(31556926);
response.addCookie(cookie);
But when I visit page /page/a, then visit page /page/b (both of which goes to the same method from controller) I notice that my Cookies (from my web dev console in Chrome) has my new cookie BEFORE my old cookie... causing the old cookie to be used by the client. I've tested this also in Firefox. What am I doing wrong?
It turned out I needed to specify the correct path for the cookie, so I just set the cookie's path to /
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With