I want to get the value of HashMap
based on key.
HashMap<String, ArrayList<String>> map
= new HashMap<String, ArrayList<String>>();
ArrayList<String> arrayList = new ArrayList<String>();
map.put("key", arrayList);
request.setAttribute("key", map);
What i did is
<c:forEach var="map" items="${requestScope.key}">
<c:forEach var="hash" items="${map.value}">
<option><c:out value="${hash}"/></option>
</c:forEach>
</c:forEach>
But it seems it's printing everything, what i want to do is to get the value depends on key like: hash.key
or something
UPDATE:
I did something like this but it still doesn't work
<c:forEach var="map" items="${requestScope.key}">
<c:forEach var="hash" items="${map['key']}">
<option><c:out value="${hash}"/></option>
</c:forEach>
</c:forEach>
and the StackTrace: Property 'External' not found on type java.util.HashMap$Entry
I'm pretty sure that there is really that kind of key.
could you please try below code
<c:forEach var="hash" items="${map['key']}">
<option><c:out value="${hash}"/></option>
</c:forEach>
I had issue with the solutions mentioned above as specifying the string key would give me javax.el.PropertyNotFoundException. The code shown below worked for me. In this I used status to count the index of for each loop and displayed the value of index I am interested on
<c:forEach items="${requestScope.key}" var="map" varStatus="status" >
<c:if test="${status.index eq 1}">
<option><c:out value=${map.value}/></option>
</c:if>
</c:forEach>
Source: Stackoverflow.com