我有一个像这样的bean,它将json Object(mappedData)返回给jsp。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ICT and Defence - Home</title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<link rel="stylesheet" type="text/css" href="responsive.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="myScript.js"></script>
<link href='http://fonts.googleapis.com/css?family=Lobster|Oswald|Pacifico|Bangers|Anton|Sigmar One' rel='stylesheet' type='text/css'>
<style>
#home-nav {
border-bottom: 2px solid;
}
</style>
</head>
<body>
<!---JavaScript SDK // For Social Media -->
<!---End of JavaScript -->
<!--header moite-->
<header>
<div id="header-container">
<h1>ICT and Defence</h1>
</div>
<!--Navigation-->
<nav>
<div id="nav-wrapper">
<ul id="main-menu">
<li><a id="home-nav" href="index.html">Home</a>
</li>
<li><a id="communication-nav" href="communication.html">Communication</a>
</li>
<li><a id="drones-nav" href="drones.html">Drones</a>
</li>
<li><a id="future-nav" href="future.html">Future Soldiers</a>
</li>
</ul>
</div>
</nav>
</header>
<div id="container">
<div id="center-div">
<div id="home-video">
<h3>Introduction</h3>
<h4 class="h4-home">Communication</h4>
<p class="info">The first military communications included the utilization of runners or the sending and receiving of simple signs, basic encrypted messages were sometimes used to conceal the information only for the onlooker.</p>
<div class="hidden">
<p class="info">The first distinctive employments of military interchanges were called "signals". Cutting edge units work in these strategies are typically assigned as "sign corps". The Roman arrangement of military correspondence is an early case of this.
Later, the expressions "signs" and "signaller" got to be words alluding to an exceedingly unmistakable military occupation managing general specialized systems (like those in common utilization) instead of with weapons.</p>
</div>
<button class="hide">Expand</button>
</div>
<div id="home-video2">
<h4 class="h4-home">Drones</h4>
<p class="info">The first military communications included the utilization of runners or the sending and receiving of simple signs, basic encrypted messages were sometimes used to conceal the information only for the onlooker.</p>
<div class="hidden">
<p class="info">The first distinctive employments of military interchanges were called "signals". Cutting edge units work in these strategies are typically assigned as "sign corps". The Roman arrangement of military correspondence is an early case of this.
Later, the expressions "signs" and "signaller" got to be words alluding to an exceedingly unmistakable military occupation managing general specialized systems (like those in common utilization) instead of with weapons.</p>
</div>
<button class="hide">Expand</button>
</div>
<div id="home-video3">
<h4 class="h4-home">Future Soldiers</h4>
<p class="info">The first military communications included the utilization of runners or the sending and receiving of simple signs, basic encrypted messages were sometimes used to conceal the information only for the onlooker.</p>
<div class="hidden">
<p class="info">The first distinctive employments of military interchanges were called "signals". Cutting edge units work in these strategies are typically assigned as "sign corps". The Roman arrangement of military correspondence is an early case of this.
Later, the expressions "signs" and "signaller" got to be words alluding to an exceedingly unmistakable military occupation managing general specialized systems (like those in common utilization) instead of with weapons.</p>
</div>
<button class="hide">Expand</button>
</div>
<!---
<div id="home-video2">
<h4 class="h4-home">Communication</h4>
<iframe src="https://www.youtube.com/embed/G2_Q9FoD-oQ" frameborder="0" allowfullscreen></iframe>
<p class="info">158,962,555,217,826,360,000 (Enigma Machine) - Numberphile</p>
</div>
<div id="home-video3">
<h4 class="h4-home">Future Of Defence</h4>
<iframe src="https://www.youtube.com/embed/S3VIpw0HAko" frameborder="0" allowfullscreen></iframe>
<p class="info">Top 10 Futuristic Military Weapons in Development</p>
</div>
-->
</div>
</div>
<footer>
<p>KIT106 - Assignment 2</p>
</footer>
</body>
</html>
我还有jsp,我需要获取exampleMap并显示键。 所以我正在做以下事情。
final Map<String, TreeMap<String, List<String>>> exampleMap = wFAServiceProxy .fetch();
mappedData.put("exampleMap ", exampleMap );
retrun mappedData;
但是我遇到了这个问题。我搜索了很多,但无法找到解决方案。
<c:forEach items='${serviceDetailFormData.get("exampleMap ")}' var="category">
<a:dropdownOption value="${category.key}">${category.key} </a:dropdownOption>
</c:forEach>
如果我打印exampleMap thorugh jsp。它显示了这个
Caused by: javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>
at org.apache.taglibs.standard.tag.common.core.ForEachSupport.toForEachIterator(ForEachSupport.java:308)
at org.apache.taglibs.standard.tag.common.core.ForEachSupport.supportedTypeForEachIterator(ForEachSupport.java:272)
at org.apache.taglibs.standard.tag.common.core.ForEachSupport.prepare(ForEachSupport.java:189)
at javax.servlet.jsp.jstl.core.LoopTagSupport.doStartTag(LoopTagSupport.java:287)
at org.apache.jsp.WEB_002dINF.views.serviceDetail_jsp._jspx_meth_c_005fforEach_005f1(serviceDetail_jsp.java:3152)
at org.apache.jsp.WEB_002dINF.views.serviceDetail_jsp._jspx_meth_a_005fdropdown_005f1(serviceDetail_jsp.java:3094)
at org.apache.jsp.WEB_002dINF.views.serviceDetail_jsp._jspx_meth_a_005fgridColumn_005f32(serviceDetail_jsp.java:3046)
at org.apache.jsp.WEB_002dINF.views.serviceDetail_jsp._jspx_meth_a_005fgridRow_005f9(serviceDetail_jsp.java:2926)
at org.apache.jsp.WEB_002dINF.views.serviceDetail_jsp._jspx_meth_a_005fform_005f0(serviceDetail_jsp.java:662)
at org.apache.jsp.WEB_002dINF.views.serviceDetail_jsp._jspx_meth_a_005fgridColumn_005f1(serviceDetail_jsp.java:488)
at org.apache.jsp.WEB_002dINF.views.serviceDetail_jsp._jspx_meth_c_005fif_005f0(serviceDetail_jsp.java:435)
at org.apache.jsp.WEB_002dINF.views.serviceDetail_jsp._jspx_meth_a_005fgridRow_005f0(serviceDetail_jsp.java:357)
at org.apache.jsp.WEB_002dINF.views.serviceDetail_jsp._jspx_meth_a_005fbody_005f0(serviceDetail_jsp.java:238)
at org.apache.jsp.WEB_002dINF.views.serviceDetail_jsp._jspService(serviceDetail_jsp.java:188)
但我想迭代它。任何人都可以帮忙。
答案 0 :(得分:0)
与Java一样,您必须调用<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
<tbody>
<tr>
<td>
<a class="mainlevel">click</a>
</td>
</tr>
<tr>
<td>
<a class="hide sublevel">a</a>
</td>
</tr>
<tr>
<td>
<a class="hide sublevel">b</a>
</td>
</tr>
<tr>
<td>
<a class="mainlevel">click</a>
</td>
</tr>
<tr>
<td>
<a class="hide sublevel">c</a>
</td>
</tr>
</tbody>
</table>
来迭代映射条目:
entrySet()
或者,如果JSP不需要进行地图查找,请将条目集放入数据中:
<c:forEach items='${serviceDetailFormData.get("exampleMap ").entrySet()}' var="category">
<a:dropdownOption value="${category.key}">${category.key} </a:dropdownOption>
</c:forEach>
答案 1 :(得分:0)
<c:forEach items='${serviceDetailFormData.get()}' var="category">
<a:dropdownOption value="${category.key}">${category.key} </a:dropdownOption>
</c:forEach>
而不是
<c:forEach items='${serviceDetailFormData.get("exampleMap ")}' var="category">
<a:dropdownOption value="${category.key}">${category.key} </a:dropdownOption>
</c:forEach>
答案 2 :(得分:0)
以下解决了我的问题
<c:forEach items='${serviceDetailFormData..get("exampleMap ").keys()}' var="category">
<a:dropdownOption value="${category.key}">${category.key} </a:dropdownOption>
</c:forEach>