Apache Commons MultiHashMap is deprecated , you should use MultiValueMap instead.
Outdated . The class is now available as a MultiValueMap in the map subpackage. This version should be removed in v4.0 collections.
Both the MultiHashMap and MultiValueMap classes have a getCollection(Object key) method that returns a collection of values ββfor this particular key:
java.util.Collection getCollection(java.lang.Object key)
Gets the collection associated with the specified key.
You can iterate over it in JSP like any other collection using JSTL, OGNL, etc.
EDIT
Surprisingly, there is not even one example of using this class in JSTL or OGNL all over the Internet ... I think your question will become popular, +1;)
Since the MultiValueMap (and the obsolete MultiHashMap) is a map with a collection of values ββfor each map key, it should be repeated in JSTL, like this one (untested, but supposedly correct) ( now TESTED on JSTL 1.1.2 in the Servlet 2.4 / JSP 2.0 container ) :
<c:forEach var="entry" items="${multiMap}"> <br/>-> Key: <c:out value="${entry.key}"/> <br/>-> Values for this key: <c:forEach var="currentValue" items="${entry.value}"> <br/>|---> value: <c:out value="${currentValue}"/> </c:forEach> </c:forEach>
Filling this type
multiMap = new MultiValueMap(); multiMap.put("key1", "value1-1"); multiMap.put("key1", "value1-2"); multiMap.put("key1", "value1-3"); multiMap.put("key2", "value2-1"); multiMap.put("key2", "value2-2"); multiMap.put("key2", "value2-3"); multiMap.put("key3", "value3-1"); multiMap.put("key3", "value3-2"); multiMap.put("key3", "value3-3");
The result is this (copied and pasted from my JSP):
-> Key: key1 -> Values for this key: |---> value: value1-1 |---> value: value1-2 |---> value: value1-3 -> Key: key3 -> Values for this key: |---> value: value3-1 |---> value: value3-2 |---> value: value3-3 -> Key: key2 -> Values for this key: |---> value: value2-1 |---> value: value2-2 |---> value: value2-3
Then it works fine (except for the curious fact that key3 fits up to key2); if you still have problems, they are not code related, but in your configuration.
Please check out the JSTL wiki tags on SO , this good article or the numerous answers to JSTL problems from BalusC here on SO.
As a final point, although looking at the code that you use to create the MultiValueMap, I highly recommend that you start creating some custom object , as object-oriented programming suggests, to avoid over-nesting lists and Maps, which can lead to unreadable, unreachable code.