2014-12-21 119 views
1
HashMap<HashMap<Integer, Integer>, String> myMap = new HashMap<HashMap<Integer, Integer>, String>(); 

HashMap<Integer, Integer> mmm = new HashMap<Integer, Integer>(); 
mmm.put(1, 2); 
myMap.put(mmm, "la"); 

mmm = new HashMap<Integer, Integer>(); 
mmm.put(2, 3); 
myMap.put(mmm, "ololo"); 

如何通過密鑰從JSP頁面訪問myMap? 我需要這樣的東西JSP訪問中的HashMap <HashMap <Integer,Integer>,String>

<td>${myMap[2][3]}</td> 

打印

<td>ololo</td> 
+0

爲什麼使用HashMap作爲單個值的關鍵?你確定這是你想要的嗎? –

+0

有簡單的例子 – Artik

回答

0

您需要創建地圖像MMM從MYMAP訪問值。 Chek下面的jsp代碼。

<% HashMap<Integer, Integer> mmm1 = new HashMap<Integer, Integer>(); 
mmm1.put(2, 3); 
%> 
<td><%=(myMap.get(mmm1)) %></td> 
+0

我需要這樣的,但沒有<%的標籤,只有JSP – Artik

0
<c:forEach var="outEntry" items="${myMap}"> 
    <c:forEach var="inEntry" items="${outEntry.key}"> 
    <c:if test="${inEntry.key== 2 && inEntry.value==3}"> 
     <td><c:out value="${outEntry.value}"/></td> 
    </c:if> 
    </c:forEach> 
</c:forEach> 

您可以檢索使用JSTL。

+0

我不需要foreach,我需要通過鍵直接訪問 – Artik

+0

@Artik我不認爲它可能通過在沒有迭代JSTL中使用鍵獲取地圖。 –

相關問題