The moose likes Servlets and the fly likes where cookies disappeared? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "where cookies disappeared?" Watch "where cookies disappeared?" New topic

where cookies disappeared?

Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
i have a servlet called "test". i have another servlet called "readCookie" and a perl script called "readCookie".
i am inserting cookies in the response from servlet "test" and i have an option of REDIRECTING the request to either the "readCookie" servlet or "readCookie" perl script.
now funny thing happens about which i'm not sure for the reason beneath.
when i redirect from servlet to the servlet it reads back all cookies correctly.
when i try to redirect to the perl script and read the cookies using ENV variable "HTTP_COOKIE" it doesn't find any cookie!!
can anybody explain the reason for this? i think in the second case (perl script) it doesnt' find ENV Var HTTP_COOKIE and that is messing it up but i don't understand when HTTP_COOKIE is set or how i can make it set using servlets.
i thought of using setHeader() or addHeader() method of response object specifying the header name as HTTP_COOKIE but that seem not working for me.
please help me!
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Possibly the CGI that runs the Perl script is not in the same "web application" - how did you set the cookies up? Did you use setPath() to control the URL to which the cookies would be visible?
The rules for cookies visibility, lifetime, etc are in RFC 2109
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
hi william!
i got it! now i understood what is the requirement of setPath()/getPath() in cookies
i was redirecting request to the Perl page under /cgi/ and my servlet context was /servlet so ....the cookie wasn't visible.
i also tried one more thing. i tried to add two cookies having the same name and it did override the first cookie i had so i could only see the second cookie i set with that name. (implementing HashTable/HashMap i guess)...
thanks for your guidance. at last i am able to understand setPath()...
I agree. Here's the link:
subject: where cookies disappeared?
jQuery in Action, 3rd edition