How to save a cookie?

I am creating a cookie in a jsp script which is located at:

www.myproject.com/login/index.jsp

if I restart the browser and move there, everything works fine, I see that the cookie is saved. If I go to:

www.myproject.com

I do not see cookies. I need to set something in the cookie’s path or domain to make the cookie visible to the entire [myproject.com] domain (I just want to access the cookie from any secondary path that the user may be). I create a cookie as:

Cookie c = new Cookie("thisisatest", "foo");
c.setMaxAge(60 * 24 * 3600);
response.addCookie(c);

thank

+3
source share
2 answers

cookie. . Cookie#setPath().

Cookie c = new Cookie("thisisatest", "foo");
c.setMaxAge(60 * 24 * 3600);
c.setPath("/");
response.addCookie(c);
+6

Source: https://habr.com/ru/post/1745659/


All Articles