JSTL c標籤,fn標籤,fmt標籤 - 生活在爪窪島上 - ITeye技術網站

來源:互聯網
上載者:User

標籤: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技術網站

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.