我想迭代Map<字符串,列表>> 在java中:
final JSONObject mappedData = new JSONObject();
final Map<String, List<List<String>>> associatedUsecasesMap = new HashMap<String, List<List<String>>>();
//some code that populates map.
mappedData.put("usecaseDetailsMap",associatedUsecasesMap);
return mappedData;
在jsp中 当我用
打印时<a:text>${usecases.get('usecaseDetailsMap').get('ARRIVED')}</a:text>
我得到了
[["ABC","Realm","patluria","test","1444209946120"],["ABC","Realm","patluria","Abhinav","1444719147503"],["ABC","Realm","patluria","Abhinav","1444719147503"],["ss","Realm","patluria","sa","1443590024585"],["ABC","Realm","patluria","eef","1444382236881"],["passport","Realm","patluria","testing","1444368146430"],["ABC","Realm","patluria","eef","1444382236881"],["ABC","Realm","patluria","as","1444210103588"],["saasa","Realm","patluria","as","1444372196955"],["ABC","Realm","patluria","sasd","1444727640485"],["ABC","Realm","patluria","eef","1444382223024"],["ss","Realm","patluria","sa","1443590006005"],["asa","Realm","patluria","asa","1444386667440"],["ABC","Realm","patluria","dadda","1444639933870"],["asa","Realm","patluria","asa","1444386667440"],["ABC","Realm","patluria","sasd","1444727626874"],["ss","Realm","patluria","sa","1444414479534"],["ABC","Realm","patluria","asa","1444729340806"],["ABC","Realm","patluria","as","1444209965115"],["ss","Realm","patluria","sa","1443590024585"],["saasa","Realm","patluria","as","1444372196955"]]
但我想迭代这个,所以我这样做
<c:forEach items="${usecases.get('usecaseDetailsMap')get('ARRIVED')}" var="usecase" >
但是我收到以下错误:javax.servlet.jsp.JspTagException:不知道如何迭代提供的&#34;项目&#34;在&lt; forEach&gt;
中我可以知道如何遍历List&gt;基于指定的密钥。
答案 0 :(得分:0)
当您遍历Map
时,JSTL forEach
将其用作Map.Entry
实例。然后你可以使用entry.key
&amp; jsp中的entry.value
。因此,您可以直接在JSTL中使用Map,如下所示: -
<c:forEach var="usecaseDetails" items="${usecaseDetailsMap}">
${usecaseDetails.key} ${usecaseDetails.value}
</c:forEach>