Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setDomain() on Cookie

 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
c.setDomain(".foo.com");
options:
1. www.foo.com
2. a.b.foo.com
(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 b.foo.com. 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 www.foo.com and another subserver-like my.yahoo.com- a.b.foo.com).
please thro some light on this. also let me know any other important thing need to be keep in mind regarding this...
regards
maulin
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cookies set from one domain are visible to sub-domains, without needing to use setDomain().

http://www.coderanch.com/t/353843/Servlets/java/Cookies-across-multiple-domains

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

We set a cookie for foo.com and it is visible to a.foo.com, b.foo.com, c.foo.com, etc...
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but not to a.b.c.foo.com right? thats what i get from API...
regards
maulin
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 (.foo.com) and means that the cookie is visible to servers in a specified Domain Name System (DNS) zone (for example, www.foo.com, but not a.b.foo.com). By default, cookies are only returned to the server that sent them."
doesnt it mean that if i set cookie domain to be ".foo.com" then it's not visible in "a.b.foo.com"?. the cookie will be visible in "www.foo.com".
well, practically it works for a.b.foo.com 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 .a.com 's web server to be having domain ".c.com" then it won't be visible to any code of ".a.com" webserver...but what about ".a.com" and ".b.a.com" domains?
)
regards
maulin.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic