I have a login page at myhost:8080/auth/login
after I logged in I set a cookie by my home controller class which is at 'myhost:8080/home/
I am setting my cookie like this
Cookie myCookie = new Cookie("__JSSESSIONID", request.getSession().getId());
myCookie.setPath("/");
response.addCookie(myCookie);
but when I see it via firebug, it shows me the path "/home". I want to set cookie on root path so that can ready from other places.
Cookie myCookie = new Cookie("__JSSESSIONID", request. getSession(). getId()); myCookie. setPath("/"); response.
In your Java server, you should call cookie. setPath("/") before adding it to response. Such cookie will match all request URIs.
Set a cookie path The path parameter specifies a document location for the cookie, so it's assigned to a specific path, and sent to the server only if the path matches the current document location, or a parent: document.
c. setMaxAge(0); //it causes the cookie to be deleted. c. setMaxAge(-1); // cookie is not stored persistently and will be deleted end of the browsing session.
Here is what you need:
<Context ... sessionCookiePath="/" > ... </Context>
Check tomcat documentation for more details
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