This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes get specific cookie? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "get specific cookie?" Watch "get specific cookie?" New topic
Author

get specific cookie?

Rob Deer
Greenhorn

Joined: Jan 10, 2005
Posts: 17
all the examples i've seen to get cookies is to use getKookies, store them into an array and loop through'em . is there a way to get a specific cookie like id:20 in one step?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

Ester,
Welcome to JavaRanch!

Yes, you need to loop through the cookie array. If you somehow knew the index of the cookie in the array you could go right to it. However, the cookies are not in any particular order. So you need to loop through each one to get the cookie name and see if it is the one you are interested in.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Sumitro Palit
Ranch Hand

Joined: Dec 13, 2003
Posts: 37
In JSP 2.0 you can use EL to achieve this.
The syntax is ${wookie.wookiename}.
So, if your wookie name is id and stores a value 20,
${wookie.id} will output 20.

Please replace "w" in all "wookie"s with 'c'
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: get specific cookie?
 
Similar Threads
Cookies associated to a Session
Cookie Problem
Cookie access with EL expression
Unable to get authentication and authorization working.
why there is no getCookie(cookie name) function?