首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

jstl 惯用基础

2012-11-05 
jstl 常用基础格式化数字日期方法和其它内置字符串处理方法 函数名 函数说明 使用举例contains 判断字符串

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表示,例如<字符应该转为&lt; ${fn:escapeXml(param:info)}
indexOf 子字符串在母字符串中出现的位置 ${fn:indexOf(name, "-")}
join 将数组中的数据联合成一个新字符串,并使用指定字符格开 ${fn:join(array, ";")}
length 获取字符串的长度,或者数组的大小 ${fn:length(shoppingCart.products)}
replace 替换字符串中指定的字符 ${fn:replace(text, "-", "&#149;")}
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)}



得到页面请求参数:
${param.myname}


if-else:
<c:choose>
   <c:when test="test1">
     结果1
   </c:when>
   <c:when test="test2">
     结果2
   </c:when>
   <c:otherwise>
    否则
   </c:otherwise>
</c:choose>

如果test1=true,则执行结果1,如果test2=true,则执行结果2,如果前面条件都为false,则执行otherwise

热点排行