3

How can I get actual domain of a cookie ? getDomain(), getPath() are returning null also I have set the appropriate values.

and I am using response.addCookie(cookie)

Thanks in advance.

Regards, Prashant

David Grant
  • 13,929
  • 3
  • 57
  • 63
user1180463
  • 247
  • 11
  • 21
  • 1
    [Java Servlet API 2.5 Cookie.getDomain() always returns null](http://stackoverflow.com/q/1035356/6509) – tim_yates Jan 31 '12 at 14:03

1 Answers1

5

Cookies coming in from the browser probably don't have this data available. Only cookie name and cookie value. See the HTTP specs for what cookie headers are set by the browser and sent to the server.

Paul Grime
  • 14,970
  • 4
  • 36
  • 58
  • I can see in the browser that the cookie sent by the browser to the server contains empty (null) for domain and path attribute and value of "expires" is End of Session. The values for cookie name and value is fine. What should I do if I want domain and path to be available in my server side code. Also when I view the cookies, each and every attribute value is OK.. Please do some help – user1180463 Jan 31 '12 at 14:43
  • 1
    It is not possible. Please read the HTTP specs about cookies or see this cut-down example - http://en.wikipedia.org/wiki/HTTP_cookie#Setting_a_cookie. Note the browser only sends cookie name and value. You *will not* get the other values from the browser. Unless you knew the domain of the cookie when it was created, you will not know it solely from a browser-sent cookie. – Paul Grime Jan 31 '12 at 16:02