JSTL标签功能集锦

1、<fmt:parseNumber integerOnly="true" value="2/3" /> 结果为0

功能:fmt:parseNumber格式化小数为整数

2、${fn:substring(userInfo.username,0,1)}截取userInfo.username的第一个字符
3、${fn:length(vals)>0}求vals集合的长度
4、fmt:formatDate 的输出格式

<fmt:formatNumber  value="${user.adoptrate}" type="percent"/>   将数字转化为百分比

<fmt:formatDate value="${isoDate}" type="both"/>                    2004-5-31 23:59:59

<fmt:formatDate value="${date}" type="date"/>                       2004-4-1

<fmt:formatDate value="${isoDate}" type="time"/>                     23:59:59

<fmt:formatDate value="${isoDate}" type="date" dateStyle="default"/>   2004-5-31

<fmt:formatDate value="${isoDate}" type="date" dateStyle="short"/>     04-5-31

<fmt:formatDate value="${isoDate}" type="date" dateStyle="medium"/>  2004-5-31

<fmt:formatDate value="${isoDate}" type="date" dateStyle="long"/>     2004年5月31日

<fmt:formatDate value="${isoDate}" type="date" dateStyle="full"/>    2004年5月31日 星期一

<fmt:formatDate value="${isoDate}" type="time" timeStyle="default"/>   23:59:59

<fmt:formatDate value="${isoDate}" type="time" timeStyle="short"/>    下午11:59

<fmt:formatDate value="${isoDate}" type="time" timeStyle="medium"/>     23:59:59

<fmt:formatDate value="${isoDate}" type="time" timeStyle="long"/>    下午11时59分59秒

<fmt:formatDate value="${isoDate}" type="time" timeStyle="full"/>   下午11时59分59秒 CDT

<fmt:formatDate value="${date}" type="both" pattern="EEEE, MMMM d, yyyy HH:mm:ss Z"/>
星期四, 四月 1, 2004 13:30:00 -0600

<fmt:formatDate value="${isoDate}" type="both" pattern="d MMM yy, h:m:s a zzzz/>
31 五月 04, 11:59:59 下午 中央夏令时

 
<fmt:formatDate value="${time}" pattern="yyyy-MM-dd HH:mm:ss" />
2016-01-19 09:41:32(24)
 
 
5、JSP读取配置文件
<fmt:bundle basename="test">
   <fmt:message key="hello"></fmt:message>
</fmt:bundle>


test.properties文件:
hello=Thisisabasemsg

6、JSTL的fn方法库

1fn:contains(string, substring) 
如果参数string中包含参数substring,返回true。 

2fn:containsIgnoreCase(string, substring) 
如果参数string中包含参数substring(忽略大小写),返回true 

 

3fn:endsWith(string, suffix) 
如果参数 string 以参数suffix结尾,返回true。 
4fn:escapeXml(string) 
将有特殊意义的XML (和HTML)转换为对应的XML character entity code,并返回。
5fn:indexOf(string, substring) 
返回参数substring在参数string中第一次出现的位置。 
6fn:join(array, separator) 
将一个给定的数组array用给定的间隔符separator串在一起,组成一个新的字符串并返回。  
7fn:length(item) 
返回参数item中包含元素的数量。参数Item类型是数组、collection或者String。如果是String类型,返回值是String中的字符数。
8fn:replace(string, before, after) 
返回一个String对象。用参数after字符串替换参数string中所有出现参数before字符串的地方,并返回替换后的结果。 
9fn:startsWith(string, prefix) 
如果参数string以参数prefix开头,返回true。 
10fn:substring(string, begin, end) 
返回参数string部分字符串, 从参数begin开始到参数end位置。 
11fn:substringAfter(string, substring) 
返回参数substring在参数string中后面的那一部分字符串。 
12fn:substringBefore(string, substring) 
返回参数substring在参数string中前面的那一部分字符串。 
13fn:toLowerCase(string) 
将参数string所有的字符变为小写,并将其返回。 
14fn:toUpperCase(string) 
将参数string所有的字符变为大写,并将其返回。 
15fn:trim(string) 
去除参数string 首尾的空格,并将其返回。
 
7、
<c:if test= "${!empty attestation.searchWord }">
        <c:set value=" ${fn:split(attestation.searchWord, ',') }" var="searchWords" />
        <c:forEach items= "${searchWords }" var="searchWord">
             <span class= "later_tag2">${searchWord} </span> &nbsp;
        </c:forEach>
</c:if>
原文地址:https://www.cnblogs.com/fengzhanfei/p/6144877.html