• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Cookies

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whats wrong with using the Cookie getName() method?
 
Fes D Gaur
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I didn't test it but you should get the idea.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic