轉自 : http://blog.sina.com.cn/s/blog_6afe83bb01018ikr.html
1.fn:contains 判斷字符串是否包含另外一個字符串
(name,searchString)}">
2.fn:containsIgnoreCase 判斷字符串是否包含另外一個字符串(大小寫無關)
test="${fn:containsIgnoreCase(name,searchString)}">
3.fn:endsWith 判斷字符串是否以另外字符串結束
(filename,".txt")}">
4.fn:escapeXml 把一些字符轉成XML表示,例如<字符應該轉爲<
${fn:escapeXml(param:info)}
5.fn:indexOf 子字符串在母字符串中出現的位置 ${fn:indexOf(name,"-")}
6.fn:join 將數組中的數據聯合成一個新字符串,並使用指定字符格開 ${fn:join
(array,";")}
7.fn:length 獲取字符串的長度,或者數組的大小 ${fn:length
(shoppingCart.products)}
8.fn:replace 替換字符串中指定的字符 ${fn:replace(text, "-","•")}
9.fn:split 把字符串按照指定字符切分 ${fn:split(customerNames,";")}
10.fn:startsWith 判斷字符串是否以某個子串開始
(product.id,"100-")}">
11.fn:substring 獲取子串 ${fn:substring(zip, 6,-1)}
12.fn:substringAfter 獲取從某個字符所在位置開始的子串${fn:substringAfter
(zip,"-")}
13.fn:substringBefore 獲取從開始到某個字符所在位置的子串
${fn:substringBefore(zip,"-")}
14.fn:toLowerCase 轉爲小寫${fn.toLowerCase(product.name)}
15.fn:toUpperCase 轉爲大寫字符${fn.UpperCase(product.name)}
16.fn:trim 去除字符串前後的空格 ${fn.trim(name)}
稱呼Functions 標籤庫爲標籤庫,倒不如稱呼其爲函數庫來得更容易理解些。因爲 Functions 標籤庫並沒有提供傳統的標籤來爲JSP 頁面的工作服務,而是被用於 EL 表達式語句中。在 JSP2.0 規範下出現的 Functions 標籤庫爲 EL表達式語句提供了許多更爲有用的功能。 Functions 標籤庫分爲兩大類,共 16 個函數。
長度函數: fn:length
字符串處理函數: fn:contains 、 fn:containsIgnoreCase 、 fn:endsWith 、fn:escapeXml 、 fn:indexOf 、 fn:join 、 fn:replace 、 fn:split 、fn:startsWith 、 fn:substring 、 fn:substringAfter 、fn:substringBefore 、 fn:toLowerCase 、 fn:toUpperCase 、fn:trim
以下是各個函數的用途和屬性以及簡單示例。
9.7.1 長度函數 fn:length 函數
長度函數 fn:length 的出現有重要的意義。在 JSTL1.0 中,有一個功能被忽略了,那就是對集合的長度取值。雖然java.util.Collection 接口定義了 size 方法,但是該方法不是一個標準的 JavaBean 屬性方法(沒有get,set 方法),因此,無法通過 EL 表達式“ ${collection.size} ”來輕鬆取得。
fn:length 函數正是爲了解決這個問題而被設計出來的。它的參數爲 input,將計算通過該屬性傳入的對象長度。該對象應該爲集合類型或 String 類型。其返回結果是一個 int類型的值。下面看一個示例。