While retrieving cookies I need to use:
<c:forEach items="${cookie}" var="currentCookie">
${currentCookie.value.name} </br>
</c:forEach>
But, while using custom arrays, why we need to skip the .value function?
<c:forEach items="${myList}" var="myList">
${myList.name} </br>
</c:forEach>
Cookie contains a .getValue function() which returns the content of the cookie in string format, so how does using currentCookie.value.name work?
The
${cookie}points to aMap<String, Cookie>with the cookie name as map key and theCookieobject as map value. Every iteration over aMapin<c:forEach>gives you aMap.Entryback which in turn hasgetKey()andgetValue()methods. Your confusion is that theCookieobject has in turn also agetValue()method.It’s a
Map<String, Cookie>because it allows you easy direct access to cookie value when you already know the name beforehand. The below example assumes it to becookieName:Your list example is by the way invalid. The
varshould not refer the same name as the list itself.