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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Cookies" Watch "Cookies" New topic
Author

Cookies

Fes D Gaur
Ranch Hand

Joined: Apr 29, 2005
Posts: 54
I'm setting a cookie using:
Cookie cook = new Cookie("Key","This Value");

Right now I have to do the following to retrieve the value of the Cookie:

PrintWriter out = resp.getWriter();
Cookie cookie[] = req.getKookies();
out.println(cookie.length);
for(int i=0;i<cookie.length;i++)
out.println(cookie[i].getValue());

How do I retrieve the value of the Cookie using the key or name of the cookie?

Thanks,
Faisal
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12805
    
    5
Whats wrong with using the Cookie getName() method?
Fes D Gaur
Ranch Hand

Joined: Apr 29, 2005
Posts: 54
Using the Cookie getName() is fine. But do I have to iterate through all the cookies and use an if equals to cookie name logic to get the cookie that I want? Or can I use the getName() method to get the value of the cookie that I want directly?

Could you please write a little piece of code that retrieves a cookie by using the Cookie's name.

Thanks,
Faisal
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410



I didn't test it but you should get the idea.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cookies