>> Apparently 'cookieVal.value' is itself of a holder type. What are those two
>> types?
>
> In fact, ${cookie} is provided by EL,not me, I've no idea what type it
> is when I iterate the ${cookie}.
>>> Apparently 'cookieVal.value' is itself of a holder type. What are
>>> those two
[quoted text clipped - 5 lines]
> If you don't know the type of 'cookie', how do you know that you can
> iterate through it?
This is, of course, the heart of your problem.
As explained in
<http://www.informit.com/articles/article.aspx?p=30946&seqNum=7>
cookies is a Map. When you iterate over the Map, each iteration yields a
Map.Entry.
Your code extract (do NOT use TAB characters to indent Usenet listings):
> <c:forEach var="cookieVal" items="${cookie}">
> <c:if test="${cookieVal.key == 'abc'}">
[quoted text clipped - 4 lines]
> single cookie,but ${cookieVal.value} can not?
> btw: it really sucks...
It sucks because you didn't check the data type first, so you failed to
understand what you needed to do.
The Entry has a value - that's ${cookieVal.value} - that's the Map.Entry value
right there. The value has a type - since ${cookies} is a Map from String to
javax.servlet.http.Cookie, that's the type of the value.
<http://java.sun.com/javaee/5/docs/api/javax/servlet/http/Cookie.html>
You want the value of the Cookie, which is the value of the value of the
Map.Entry:
${cookieVal.value.value}
Gee, that doesn't suck at all, not really, not in any way.
Q.E.D.

Signature
Lew
Arved Sandstrom - 17 Mar 2008 16:21 GMT
>>>> Apparently 'cookieVal.value' is itself of a holder type. What are
>>>> those two
[quoted text clipped - 38 lines]
>
> Q.E.D.
Good explanation of those points. On a different note, why iterate over a
map if you are actually interested only in the value corresponding to one
key? A map implementation lets you test for the existence of a key. I am not
sure of the exact syntax here but I think it's something like
<c:if test="${not empty cookie["cookieName"]}">...
Don't hold me to it, but I think the above is close ('empty' apparently does
an empty test on collections but also does a null test). In any case, the
point is that it will be doable to test to see if the key ("abc") exists,
and then act on that, rather than iterate over all entries in the map.
AHS
Lew - 18 Mar 2008 02:32 GMT
> Good explanation of those points. On a different note, why iterate over a
> map if you are actually interested only in the value corresponding to one
[quoted text clipped - 5 lines]
> Don't hold me to it, but I think the above is close ('empty' apparently does
> an empty test on collections but also does a null test). In any case, the
You're correct, and more than that, 'empty' subsumes the idiom for Strings
(x == null || x.length() == 0)
Basically, 'empty' matches the obvious interpretations of the word. It's as
if it had a series of reasonable tests for each valid expression type that it
can handle.
> point is that it will be doable to test to see if the key ("abc") exists,
> and then act on that, rather than iterate over all entries in the map.

Signature
Lew