File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes setDomain() on Cookie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "setDomain() on Cookie" Watch "setDomain() on Cookie" New topic

setDomain() on Cookie

Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
hi folks!
i've a question. if i use setDomain() on the cookie tell
which one would be the correct answer.
Cookie c = new Cookie("test","testCookie");
(this is from the Java Servlet API but i want to make sure that i understand it correctly)
my answer is (1). is that right? 'coz for the cookie to be visible to (2) we need
to have DNS as am i right or missing something?
so this presicely means its only the domain which we specify to which the cookie is visible.
it is not visible to the internal servers as well. (in above example we have two servers,
one main server with and another subserver-like
please thro some light on this. also let me know any other important thing need to be keep in mind regarding this...
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

cookies set from one domain are visible to sub-domains, without needing to use setDomain().

check Mike Fuellbrandt's'post, he is a colleague of mine.

We set a cookie for and it is visible to,,, etc...
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
but not to right? thats what i get from API...
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
plz explain me the following excerpt from the API,
"The form of the domain name is specified by RFC 2109. A domain name begins with a dot ( and means that the cookie is visible to servers in a specified Domain Name System (DNS) zone (for example,, but not By default, cookies are only returned to the server that sent them."
doesnt it mean that if i set cookie domain to be "" then it's not visible in ""?. the cookie will be visible in "".
well, practically it works for i guess (with an example i ran). so am i incorrect in interpreting the API or what?
please try to provide examples of the both cases,
1. the case in which it will work (i see the cookie),
2. the case in which i won't see the cookie.
i know that, if i am setting cookie from 's web server to be having domain "" then it won't be visible to any code of "" webserver...but what about "" and "" domains?
I agree. Here's the link:
subject: setDomain() on Cookie
It's not a secret anymore!