淺談JSTL中如何利用list.size()處理IP地址
作者:wurushuang
本文將簡單談?wù)勗贘STL中如何利用list.size()處理IP地址,以及截取時間戳、自動關(guān)閉模態(tài)窗口等等內(nèi)容。JSTL(JSP Standard Tag Library ,JSP標(biāo)準(zhǔn)標(biāo)簽庫)是一個不斷完善的開放源代碼的JSP標(biāo)簽庫。JSTL只能運行在支持JSP1.2和Servlet2.3規(guī)范的容器上,如tomcat 4.x。在JSP 2.0中也是作為標(biāo)準(zhǔn)支持的。
得到list.size()
Java代碼
- ${fn:length(listComment)}
- ${fn:length(listComment)}
處理IP地址
Java代碼
- <c:forTokens var="ip" items="${comment.ip}" delims="." begin="0" end="2">${ip}.</c:forTokens>*
- <c:forTokens var="ip" items="${comment.ip}" delims="." begin="0" end="2">${ip}.</c:forTokens>*
JSTL標(biāo)簽顯示指定長度字符串
Java代碼
- <c:set var="log.logTitle" value="做一個截取字符串長度的測試"
- <c:choose>
- <c:when test="${fn:length(log.logTitle) > 10}">
- <c:out value="${fn:substring(log.logTitle, 0, 10)}......" />
- </c:when>
- <c:otherwise>
- <c:out value="${log.logTitle}" />
- </c:otherwise>
- </c:choose>
- <c:set var="log.logTitle" value="做一個截取字符串長度的測試"
- <c:choose>
- <c:when test="${fn:length(log.logTitle) > 10}">
- <c:out value="${fn:substring(log.logTitle, 0, 10)}......" />
- </c:when>
- <c:otherwise>
- <c:out value="${log.logTitle}" />
- </c:otherwise>
- </c:choose>
截取時間戳
Java代碼
- ${fn:substring(comment.time,0,19)}
- ${fn:substring(comment.time,0,19)}
自動關(guān)閉模態(tài)窗口
Java代碼
- <c:if test="${success=='ok'}" >
- <script type="text/javascript">
- alert("評論發(fā)表成功");
- parent.parent.location.reload();
- </script>
- </c:if>
- <c:if test="${success=='ok'}" >
- <script type="text/javascript">
- alert("評論發(fā)表成功");
- parent.parent.location.reload();
- </script>
- </c:if>
JSTL中varStatus和 var 屬性一樣,varStatus用于創(chuàng)建限定了作用域的變量。不過,由varStuts屬性命名的變量并不存儲當(dāng)前索引值或當(dāng)前元素,而是賦予 javax.servlet.jsp.jstl.core.LoopTagStatus 類的實例。該類定義了一組特性,它們描述了迭代的當(dāng)前狀態(tài),下面列出了這些特性:
Java代碼
- 特性 Getter 描述
- current getCurrent() 當(dāng)前這次迭代的(集合中的)項
- index getIndex() 當(dāng)前這次迭代從 0 開始的迭代索引
- count getCount() 當(dāng)前這次迭代從 1 開始的迭代計數(shù)
- first isFirst() 用來表明當(dāng)前這輪迭代是否為***次迭代的標(biāo)志
- last isLast() 用來表明當(dāng)前這輪迭代是否為***一次迭代的標(biāo)志
- begin getBegin() begin 屬性值
- end getEnd() end 屬性值
- step getStep() step 屬性值
- <c:forEach items="${listZonenews}" var="zonenews" varStatus="s">
- ${s.count}. ${zonenews.title }
- </c:forEach>
【編輯推薦】
責(zé)任編輯:彭凡
來源:
javaeye