2014-12-21 92 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中使用键获取地图。 –

相关问题