This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "get specific cookie?" Watch "get specific cookie?" New topic

get specific cookie?

Rob Deer

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

Joined: May 26, 2003
Posts: 30352

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,
${} will output 20.

Please replace "w" in all "wookie"s with 'c'
I agree. Here's the link:
subject: get specific cookie?