您的位置:首页 > Web前端 > JavaScript

JSP中foreach标签(JSTL)的使用

2017-02-28 09:51 453 查看
http://blog.csdn.net/zlxdream815/article/details/25723981

在使用foreach标签之前,需要在JSP中导入标签

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<table align="center" width="98%" border="0" cellspacing="1" cellpadding="0" class="resulttable">
<tr>
<th width="18%">卡种类型</th>
<th width="82%">卡种等级</th>
</tr>
<c:if test="${ empty command.cardList}">
<tr><td align="center" colspan="10" class="oddbgc" >无记录</td>
</tr>
</c:if>
<c:if test="${ not empty command.cardList}">
<c:forEach  var="bean" items="${ command.cardList}" varStatus="s">
<c:if test="${bean.dataLevel=='1'}">
<tr>
<td align="left" class="<c:choose ><c:when test='${s.index%2 ==0}'>oddbgc</c:when><c:otherwise>evenbgc</c:otherwise></c:choose>">
<c:out value="${bean.cardName}"/>
</td>
<td align="left" class="<c:choose ><c:when test='${s.index%2 ==0}'>oddbgc</c:when><c:otherwise>evenbgc</c:otherwise></c:choose>">
<c:forEach  var="childbean" items="${ command.cardList}" varStatus="sr">
<c:if test="${bean.cardCode eq childbean.parentCardCode}">
<c:out value="${childbean.cardName}"/>
</c:if>
</c:forEach>
</td>
</tr>
</c:if>
</c:forEach>
</c:if>
</table>


jsp页面itertor或forEach循环输出list:

http://blog.csdn.net/abcjiecba/article/details/6624970

JSP遍历后台传过来的List(总结的比较好):

三种方法:使用jstl标签

使用jsp内嵌Java代码遍历list(在后台把list放到session中)

使用struts标签

http://blog.csdn.net/kalision/article/details/8512700
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  jstl jsp 标签 foreach