JSTL標準函數總結,jstl函數總結
jstl標準函數
在使用這些函數之前必須在JSP中引入標準函數的聲明
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
下面是JSTL中內建的方法列表以及其描述
|
函數名 |
函數說明 |
使用舉例 |
|
contains |
判斷字串是否包含另外一個字串 |
<c:if test="${fn:contains(name, searchString)}"> |
|
containsIgnoreCase |
判斷字串是否包含另外一個字串(大小寫無關) |
<c:if test="${fn:containsIgnoreCase(name, searchString)}"> |
|
endsWith |
判斷字串是否以另外字串結束 |
<c:if test="${fn:endsWith(filename, ".txt")}"> |
|
escapeXml |
把一些字元轉成XML表示,例如<字元應該轉為< |
${fn:escapeXml(param:info)} |
|
indexOf |
子字串在母字串中出現的位置 |
${fn:indexOf(name, "-")} |
|
join |
將數組中的資料聯合成一個新字串,並使用指定字元格開 |
${fn:join(array, ";")} |
|
length |
擷取字串的長度,或者數組的大小 |
${fn:length(shoppingCart.products)} |
|
replace |
替換字串中指定的字元 |
${fn:replace(text, "-", "•")} |
|
split |
把字串按照指定字元切分 |
${fn:split(customerNames, ";")} |
|
startsWith |
判斷字串是否以某個子串開始 |
<c:if test="${fn:startsWith(product.id, "100-")}"> |
|
substring |
擷取子串 |
${fn:substring(zip, 6, -1)} |
|
substringAfter |
擷取從某個字元所在位置開始的子串 |
${fn:substringAfter(zip, "-")} |
|
substringBefore |
擷取從開始到某個字元所在位置的子串 |
${fn:substringBefore(zip, "-")} |
|
toLowerCase |
轉為小寫 |
${fn.toLowerCase(product.name)} |
|
toUpperCase |
轉為大寫字元 |
${fn.UpperCase(product.name)} |
|
trim |
去除字串前後的空格 |
${fn.trim(name)} |
著作權聲明:歡迎轉載,希望在你轉載的同時,添加原文地址,謝謝配合