aspose file tools
The moose likes Servlets and the fly likes addCookie() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "addCookie()" Watch "addCookie()" New topic


Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
hi all,
if i add a cookie with a same name twice what would happen?
i can try this but not now so i posted this question.
i believe that if cookies are maintained in Hashtable by the WebServer then it will overwrite the older one but if not then i don't know.
this question came across as one of my friends asked me this but i am too sure about my belief and i wont get time to test it myself
please throw some light on this.
thank you.
David Peterson
Ranch Hand

Joined: Oct 14, 2001
Posts: 154
Yes, if you add a cookie with the same name as an existing one, it is replaced.
Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401
I think that's not exactly true, but I'm not an expert on cookies.

Should create 2 cookies with the same name.

comp.lang.javascript FAQ:
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
hi Garrett,
yes. you are right. i tried the similar code. it creates two cookies if we set domain to be different.
so i guess the servlet container might be comparing two Cookie objects (not just their names) before putting cookies into response.
sounds reasonable.
thanks for your help.
It is sorta covered in the JavaRanch Style Guide.
subject: addCookie()