jstl进步篇

<body>
<h1>对map和set的迭代</h1>
<%
Map map = new HashMap();
map.put("1", "aa");
map.put("2", "bb");
//把map放入某个域对象
request.setAttribute("lstMap", map);

//set
Set set = new HashSet();
User user = new User();
user.setName("lihui");
user.setAge(20);
set.add(user);

user = new User();
user.setName("zhaoping");
user.setAge(30);
set.add(user);

user = new User();
user.setName("chengxiang");
user.setAge(10);
set.add(user);
request.setAttribute("sets", new HashSet());
request.setAttribute("lstSet", set);
%>
<h2>map</h2>
<c:forEach items="${lstMap}" var="item">
Key=${item.key };Value=${item.value }
<!-- Key=2;Value=bb Key=1;Value=aa -->
</c:forEach>

<br/>
<h2>set</h2>
<c:forEach items="${lstSet}" var="item">
${item.name }:${item.age}
</c:forEach>

<br/>
<h2>使用标签判断空</h2>
<c:if test="${empty nihao}">
没有该变量nihao
</c:if>
<br/>
<c:if test="${empty sets}">
没有元素sets
</c:if>
</body>

输出:

对map和set的迭代

map

Key=2;Value=bb Key=1;Value=aa

set

chengxiang:10 lihui:20 zhaoping:30

使用标签判断空

没有该变量nihao
没有元素sets 

原文地址:https://www.cnblogs.com/jiqiwoniu/p/jstl.html