Two Laptop Bag
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
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
author & internet detective

Joined: May 26, 2003
Posts: 33102

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, 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?
It's not a secret anymore!