Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java setting cookie on root path

Tags:

java

cookies

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.

like image 836
coure2011 Avatar asked Jun 02 '13 11:06

coure2011


People also ask

How to set cookie Path in Java?

Cookie myCookie = new Cookie("__JSSESSIONID", request. getSession(). getId()); myCookie. setPath("/"); response.

How do I set cookies to all path?

In your Java server, you should call cookie. setPath("/") before adding it to response. Such cookie will match all request URIs.

What is path in set cookie?

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.

How to delete cookies from server side in Java?

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.


1 Answers

Here is what you need:

<Context ... sessionCookiePath="/" > ... </Context>

Check tomcat documentation for more details

like image 133
Chris Avatar answered Oct 11 '22 01:10

Chris