循环控制主要有两个标签:<c:forEach><c:forTokens>。下面一次介绍这两个标签的使用。
【c:forEach】
语法格式:

属性:
①用forEach标签循环遍历实体集合
<h3>采用forEach标签</h3>
<table >
<tr>
<td>用户名称</td>
<td>年龄</td>
<td>所属组</td>
</tr>
<c:choose>
<c:when test="${empty users}">
<tr>
<td colspan="3">没有符合条件的数据</td>
</tr>
</c:when>
<c:otherwise>
<c:forEach items="${users}" var="user">
<tr>
<td>${user.username }</td>
<td>${user.age }</td>
<td>${user.group.name }</td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>
②forEach循环遍历实体集合,用双数行变红(varStatus属性)
<h3>采用forEach标签,varstatus</h3><br>
<table >
<tr>
<td>用户名称</td>
<td>年龄</td>
<td>所属组</td>
</tr>
<c:choose>
<c:when test="${empty users}">
<tr>
<td colspan="3">没有符合条件的数据</td>
</tr>
</c:when>
<c:otherwise>
<c:forEach items="${users}" var="user" varStatus="vs">
<c:choose>
<c:when test="${vs.count mod 2 == 0}">
<tr bgcolor="red">
</c:when>
<c:otherwise>
<tr>
</c:otherwise>
</c:choose>
<td>${user.username }</td>
<td>${user.age }</td>
<td>${user.group.name }</td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>
③用forEach循环遍历实体集合,显示指定条数
<h3>采用forEach标签,begin,end</h3>
<table >
<tr>
<td>用户名称</td>
<td>年龄</td>
<td>所属组</td>
</tr>
<c:choose>
<c:when test="${empty users}">
<tr>
<td colspan="3">没有符合条件的数据</td>
</tr>
</c:when>
<c:otherwise>
<c:forEach items="${users}" var="user" begin="2" end="8" step="2">
<tr>
<td>${user.username }</td>
<td>${user.age }</td>
<td>${user.group.name }</td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>
④forEach循环遍历map
<li>演示循环控制标签:forEach,输出map</li>
<br>
<c:forEach items="${map}" var="entry">
${entry.key },${entry.value }<br>
</c:forEach>
【c:forTokens】
语法格式:
属性:
用于输出有使用特殊符号来分隔内容的数据。
<li>演示循环控制标签:forTokens</li>
<br>
<c:forTokens items="${strTokens}" delims="#" var="v">
${v }<br>
</c:forTokens>