前提:c標籤的引入:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
一:在<c:forEach>中添加序號的方法:
在<c:forEach>標籤中添加屬性:varStatus;
然後${varStatus的屬性值.index}:序號從0開始;${varStatus的屬性值.index+1}:序號從1開始
OR直接:${varStatus的屬性值.count}:序號從1開始
例子如下:
<tr height="30">
<th width="130" >序號:</th>
</tr>
<c:forEach items="${result }" var="res" varStatus="status" >
<tr>
<td>${status.index+1 }</td>
</tr>
效果如下:
二:對c標籤中數據的選擇和判斷
這裏我們要用到如下幾個標籤:
<c:choose>
<c:when test="${res.vendibility eq 0 }">test</c:when>
<c:otherwise>${res.vendibility}</c:otherwise>
</c:choose>
<c:choose> | 本身只當做<c:when>和<c:otherwise>的父標籤 |
<c:when> | <c:choose>的子標籤,用來判斷條件是否成立 |
<c:otherwise> | <c:choose>的子標籤,接在<c:when>標籤後,當<c:when>標籤判斷爲false時被執行 |
三:有關fn函數的使用:
jstl標籤庫fn函數介紹:
stl標籤庫fn函數就是在jsp頁面或js代碼裏面使用的函數,它是建立在EL表達式基礎上的表達式函數,格式爲 ${ns:methodName(args....)},一般會結合jstl標籤庫核心標籤C標籤使用。
fn函數使用示例:
<c:if test="${fn:contains(name, searchString)}"></c:if>
var arrStr = ${fn:join(array, ";")};