標籤:http io ar 使用 sp java for div on
jstl是sun定義的標準,由apache實現,所以要下載jar包的話去apache,要看api文檔的話,去sun,API文檔在此:http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/index.html
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
c標籤庫的使用不做介紹,簡單寫下不常用的幾個
1、c:forTokens
類似於js及java中的split函數,將一個字串用某個字元分割成數組,然後逐個處理。items是需要處理的原始字串,delims是分隔字元
<c:forTokens var="item" items="www.trs.com.cn" delims=".">
${item }<br/>
</c:forTokens>
2、fmt.tld中比較有用的fmt:parseDate, fmt:formatDate, fmt:parseNumber, fmt:formatNumber,用來格式化時間與數字,例子如下:
<fmt:formatDate value="${item.createdTime }" pattern="yyyy-MM-dd HH:mm" />
3、fn.tld,jstl的函數,其中有
fn:contains 判斷一個字串是否含有另外一個字串,eg <c:if test="${fn:contains(str, searchString)}">;
fn:containsIgnoreCase 同上面的tag,只是不區分大小寫;
fn:endsWith 判斷一個字串是否以某個字串結束,eg <c:if test="${fn:endsWith(filename, ".txt")}">
fn:escapeXml 將字串轉換為沒有xml無法識別字元的字串,eg ${fn:escapeXml(info)}
fn:indexOf 判斷某個字元在一個字串中的位置,eg ${fn:indexOf(name, "-")}
fn:join 同jsjoin,將數組用字元拼接,eg ${fn:join(array, ";")}
fn:length 計算字串的長度
fn:replace 替換某個字串, eg ${fn:replace(text, "-", "?")}
fn:split join的反過程,eg ${fn:split(customerNames, ";")}
fn:startsWith 是否以某個字串開始, eg <c:if test="${fn:startsWith(product.id, "100-")}">
fn:substring 擷取字串,eg ${fn:substring(zip, 6, -1)}
fn:substringAfter 從某個字串開始取字串,eg ${fn:substringAfter(zip, "-")}
fn:substringBefore 上一條的反過程
fn:toUpperCase 把字串中的字元全部轉為大寫
fn:trim 去掉字串兩邊的空格,eg ${fn.trim(name)}
來自為知筆記(Wiz)
JSTL c標籤,fn標籤,fmt標籤 - 生活在爪窪島上 - ITeye技術網站