Get value from hashmap based on key to JSTL

后端 未结 3 369
余生分开走
余生分开走 2020-12-05 04:27

I want to get the value of HashMap based on key.

HashMap> map 
    = new HashMap

        
相关标签:
3条回答
  • 2020-12-05 04:32

    could you please try below code

    <c:forEach var="hash" items="${map['key']}">
            <option><c:out value="${hash}"/></option>
      </c:forEach>
    
    0 讨论(0)
  • 2020-12-05 04:41

    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>    
    
    0 讨论(0)
  • 2020-12-05 04:48

    if all you're trying to do is get the value of a single entry in a map, there's no need to loop over any collection at all. simplifying gautum's response slightly, you can get the value of a named map entry as follows:

    <c:out value="${map['key']}"/>
    

    where 'map' is the collection and 'key' is the string key for which you're trying to extract the value.

    0 讨论(0)
提交回复
热议问题