File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cookies

 
Fes D Gaur
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whats wrong with using the Cookie getName() method?
 
Fes D Gaur
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I didn't test it but you should get the idea.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic