I have three maps having data in it. How can i display it in a table in jsp page.
Iterate each map using <c:forEach>
<table>
<c:forEach items="#{map1}" var="item1">
<tr>
<td><c:out value="#{item1.key}" /></td>
<td><c:out value="#{item1.value}" </td>
</tr>
</c:forEach>
Merge three Map in to one .
Map<String, Integer> map1 = new HashMap<String, Integer>();
Map<String, Integer> map2 = new HashMap<String, Integer>();
Map<String, Integer> map3 = new HashMap<String, Integer>();
Map<String, Integer> combinedMap = new HashMap<String, Integer>();
combinedMap.putAll(map1);
combinedMap.putAll(map2);
combinedMap.putAll(map3);
Then Iterate on combinedMap
.
<c:forEach items="#{combinedMap}" var="item1">
There are more than one way to accomplish this (one of them):
By using JSP Standard Tag Library (JSTL) c:forEach
Tag as follows:
<c:set value="${sessionScope.sessionObject.map1}" var="map1">
<c:set value="${sessionScope.sessionObject.map1}" var="map2">
<c:set value="${sessionScope.sessionObject.map1}" var="map3">
<c:forEach items="${map1}" var="item1">
<tr>
<td><c:out value="${item1.key}" /></td>
<td><c:out value="${item1.value}" </td>
</tr>
</c:forEach>
<c:forEach items="${map2}" var="item1"> .... etc
Or join them in one map and then iterate.
To solve this problem i used the MultiMap from apache commons collections. This can also be solved if i create a DTO for data to be sent on jsp.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.