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

Retrieving Cookies

padmanabh dongre

Joined: Aug 13, 2001
Posts: 24
I am reading the cookies from the client machine to see whether , he has previously visited my site. currently i invoke a method request.getCookies() to get all the cookies and then loop thru them to find out whether the required cookie is there or not. Is there a method or a way to find out directly whether he has the cookies from my site. or everytime i have to loop thru all the cookies on his machine ( this takes time if he has lot of cookies).
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
request.getCookies() returns only the cookies sent with this particular request, not every cookie on the user's machine.
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets

Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
Tony Alicea

Joined: Jan 30, 2000
Posts: 3226
    5 if you (padmanabh) do not get any cookies when you call the method getCookies(), then there are not any that you previously sent.
Well, almost.
The servlet API allows you to sate
That domain could be any domain. So theoretically you could send a cookie from a domain so that ANOTHER domain may read it. Unless you have Netscape 4.x (and I hope 6.x) where you can choose the option "Accept only cookies that get sent back to the originating server".

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
I agree. Here's the link:
subject: Retrieving Cookies
It's not a secret anymore!