背景:servlet中的map,提交到JSP:
Map<String, String> sParaTemp = new HashMap<String, String>();
sParaTemp.put("time", currentTime);
sParaTemp.put("count", count));
request.setAttribute("trademap", sParaTemp);
request.getRequestDispatcher("/order.jsp").forward(request,
response);
jsp:遍历读取:
<c:if test="${!empty trademap}">
<!-- 查询到的数据集不为空的情况 -->
<c:forEach items="${trademap}" var="sd">
<td><input size="30" style="border-style: none"name="a" value="${sd.time}" /></td>
这个${sd.time}",time报错:Property 'time' not found on type java.lang.String
到底该怎么取到map 中的值?
答案:
${tradmap[
'time'
]}
|
假如你想遍历map所有的值,可以往request里面放入一个key的list
1
2
3
4
|
List<String> list =
new
ArrayList<String>();
list.add(
"time"
);
list.add(
"count"
);
request.setAttribute(
"list"
, list);
|
然后在页面遍历
1
2
3
4
5
6
7
|
<c:
if
test=
"${!empty trademap}"
>
<c:forEach items=
"${trademap}"
var
=
"sd"
>
<c:forEach items=
"${list }"
var
=
"keys"
>
${sd[keys]} <!-- 这就遍历出所有的value了 -->
</c:forEach>
</c:forEach>
</c:
if
>
|