Re: Is there a easy way to get complete info about JSTL and EL?
Lew wrote:
lightning wrote:
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}.
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'}">
<c:out value="${cookieVal.value.value}"></c:out>
</c:if>
</c:forEach>
only ${cookieVal.value.value} can output the right value of that
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.
--
Lew