1.<c:if>
用于实现 java 中的 if 语句功能。
<c:if test=”${list.fenhuo==1}”>
<td><font color="red">${list.fenhuo}</font></td>
</c:if>
如果test为true时,单元格的字体设置为红色。
2.<c:choose><c:when><c:otherwise>经常一块使用,例如下面我工作中遇到的
<c:choose>
<c:when test="${list.fenhuo==1||list.fenhuo==2||list.fenhuo==3||list.fenhuo==4}">
<td><font color="red">${list.fenhuo}</font></td>
</c:when>
<c:otherwise>
<td>${list.fenhuo}</td>
</c:otherwise>
</c:choose>
这实现的功能是当这列的值为1或2或3或4时这列显示为红色,其他显示正常。
<c:choose> <c:when><c:otherwise>用法相当于if else的实现功能,当有多个判定条件的时候可以写多个<c:when>。
3.<c:foreach>用法
<c:forEach var="list" items="${page.rows}" varStatus="stauts" begin="开始下标" end="数据源长度" step="迭代的长度">
<td>${stauts.count}</td>
</c:forEach>
后面三个参数可以不写,<td>${stauts.count}</td> 是在列表中显示序号。
var:迭代参数的名称。
items:要进行迭代的集合。
varStatus:迭代变量的名称,用来表示迭代的状态,可以访问到迭代自身的信息。
begin:如果指定了items,那么迭代就从items[begin]开始进行迭代;如果没有指定items,那么就从begin开始迭代。它的类型为整数。
end:如果指定了items,那么就在items[end]结束迭代;如果没有指定items,那么就在end结束迭代。它的类型也为整数。
step:迭代的步长。