1 <?xml version="1.0" encoding="UTF-8" ?>
2
3 <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
6 version="2.0">
7
8 <description>JSTL 1.1 functions library</description>
9 <display-name>JSTL functions</display-name>
10 <tlib-version>1.1</tlib-version>
11 <short-name>fn</short-name>
12 <uri>http://java.sun.com/jsp/jstl/functions</uri>
13
14 <function>
15 <description>
16 Tests if an input string contains the specified substring.
17 </description>
18 <name>contains</name>
19 <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
20 <function-signature>boolean contains(java.lang.String, java.lang.String)</function-signature>
21 <example>
22 <c:if test="${fn:contains(name, searchString)}">
23 </example>
24 </function>
25
26 <function>
27 <description>
28 Tests if an input string contains the specified substring in a case insensitive way.
29 </description>
30 <name>containsIgnoreCase</name>
31 <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
32 <function-signature>boolean containsIgnoreCase(java.lang.String, java.lang.String)</function-signature>
33 <example>
34 <c:if test="${fn:containsIgnoreCase(name, searchString)}">
35 </example>
36 </function>
37
38 <function>
39 <description>
40 Tests if an input string ends with the specified suffix.
41 </description>
42 <name>endsWith</name>
43 <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
44 <function-signature>boolean endsWith(java.lang.String, java.lang.String)</function-signature>
45 <example>
46 <c:if test="${fn:endsWith(filename, ".txt")}">
47 </example>
48 </function>
49
50 <function>
51 <description>
52 Escapes characters that could be interpreted as XML markup.
53 </description>
54 <name>escapeXml</name>
55 <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
56 <function-signature>java.lang.String escapeXml(java.lang.String)</function-signature>
57 <example>
58 ${fn:escapeXml(param:info)}
59 </example>
60 </function>
61
62 <function>
63 <description>
64 Returns the index withing a string of the first occurrence of a specified substring.
65 </description>
66 <name>indexOf</name>
67 <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
68 <function-signature>int indexOf(java.lang.String, java.lang.String)</function-signature>
69 <example>
70 ${fn:indexOf(name, "-")}
71 </example>
72 </function>
73
74 <function>
75 <description>
76 Joins all elements of an array into a string.
77 </description>
78 <name>join</name>
79 <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
80 <function-signature>java.lang.String join(java.lang.String[], java.lang.String)</function-signature>
81 <example>
82 ${fn:join(array, ";")}
83 </example>
84 </function>
85
86 <function>
87 <description>
88 Returns the number of items in a collection, or the number of characters in a string.
89 </description>
90 <name>length</name>
91 <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
92 <function-signature>int length(java.lang.Object)</function-signature>
93 <example>
94 You have ${fn:length(shoppingCart.products)} in your shopping cart.
95 </example>
96 </function>
97
98 <function>
99 <description>
100 Returns a string resulting from replacing in an input string all occurrences
101 of a "before" string into an "after" substring.
102 </description>
103 <name>replace</name>
104 <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
105 <function-signature>java.lang.String replace(java.lang.String, java.lang.String, java.lang.String)</function-signature>
106 <example>
107 ${fn:replace(text, "-", "•")}
108 </example>
109 </function>
110
111 <function>
112 <description>
113 Splits a string into an array of substrings.
114 </description>
115 <name>split</name>
116 <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
117 <function-signature>java.lang.String[] split(java.lang.String, java.lang.String)</function-signature>
118 <example>
119 ${fn:split(customerNames, ";")}
120 </example>
121 </function>
122
123 <function>
124 <description>
125 Tests if an input string starts with the specified prefix.
126 </description>
127 <name>startsWith</name>
128 <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
129 <function-signature>boolean startsWith(java.lang.String, java.lang.String)</function-signature>
130 <example>
131 <c:if test="${fn:startsWith(product.id, "100-")}">
132 </example>
133 </function>
134
135 <function>
136 <description>
137 Returns a subset of a string.
138 </description>
139 <name>substring</name>
140 <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
141 <function-signature>java.lang.String substring(java.lang.String, int, int)</function-signature>
142 <example>
143 P.O. Box: ${fn:substring(zip, 6, -1)}
144 </example>
145 </function>
146
147 <function>
148 <description>
149 Returns a subset of a string following a specific substring.
150 </description>
151 <name>substringAfter</name>
152 <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
153 <function-signature>java.lang.String substringAfter(java.lang.String, java.lang.String)</function-signature>
154 <example>
155 P.O. Box: ${fn:substringAfter(zip, "-")}
156 </example>
157 </function>
158
159 <function>
160 <description>
161 Returns a subset of a string before a specific substring.
162 </description>
163 <name>substringBefore</name>
164 <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
165 <function-signature>java.lang.String substringBefore(java.lang.String, java.lang.String)</function-signature>
166 <example>
167 Zip (without P.O. Box): ${fn:substringBefore(zip, "-")}
168 </example>
169 </function>
170
171 <function>
172 <description>
173 Converts all of the characters of a string to lower case.
174 </description>
175 <name>toLowerCase</name>
176 <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
177 <function-signature>java.lang.String toLowerCase(java.lang.String)</function-signature>
178 <example>
179 Product name: ${fn:toLowerCase(product.name)}
180 </example>
181 </function>
182
183 <function>
184 <description>
185 Converts all of the characters of a string to upper case.
186 </description>
187 <name>toUpperCase</name>
188 <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
189 <function-signature>java.lang.String toUpperCase(java.lang.String)</function-signature>
190 <example>
191 Product name: ${fn:UpperCase(product.name)}
192 </example>
193 </function>
194
195 <function>
196 <description>
197 Removes white spaces from both ends of a string.
198 </description>
199 <name>trim</name>
200 <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
201 <function-signature>java.lang.String trim(java.lang.String)</function-signature>
202 <example>
203 Name: ${fn:trim(name)}
204 </example>
205 </function>
206
207 </taglib>
上述是http://java.sun.com/jsp/jstl/functions的源代码
用来弥补JSTL在处理字符串上的缺陷
使用的方式
一、
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
二、
在WEB-INF目录下创建functions.ltd
然后将上述代码拷进去
<%@ taglib prefix="fn" uri="/WEB-INF/functions.tld" %>
或则
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
区别在于说这样的话即使不联网也可以使用
<!-- 函数说明 -->
函数名 | 函数说明 | 使用举例 |
fn:contains | 判断字符串是否包含另外一个字符串 | <c:if test="${fn:contains(name, searchString)}"> |
fn:containsIgnoreCase | 判断字符串是否包含另外一个字符串(大小写无关) | <c:if test="${fn:containsIgnoreCase(name, searchString)}"> |
fn:endsWith | 判断字符串是否以另外字符串结束 | <c:if test="${fn:endsWith(filename, ".txt")}"> |
fn:escapeXml | 把一些字符转成XML表示,例如<字符应该转为< | ${fn:escapeXml(param:info)} |
fn:indexOf | 子字符串在母字符串中出现的位置 | ${fn:indexOf(name, "-")} |
fn:join | 将数组中的数据联合成一个新字符串,并使用指定字符格开 | ${fn:join(array, ";")} |
fn:length | 获取字符串的长度,或者数组的大小 | ${fn:length(shoppingCart.products)} |
fn:replace | 替换字符串中指定的字符 | ${fn:replace(text, "-", "•")} |
fn:split | 把字符串按照指定字符切分 | ${fn:split(customerNames, ";")} |
fn:startsWith | 判断字符串是否以某个子串开始 | <c:if test="${fn:startsWith(product.id, "100-")}"> |
fn:substring | 获取子串 | ${fn:substring(zip, 6, -1)} |
fn:substringAfter | 获取从某个字符所在位置开始的子串 | ${fn:substringAfter(zip, "-")} |
fn:substringBefore | 获取从开始到某个字符所在位置的子串 | ${fn:substringBefore(zip, "-")} |
fn:toLowerCase | 转为小写 | ${fn.toLowerCase(product.name)} |
fn:toUpperCase | 转为大写字符 | ${fn.UpperCase(product.name)} |
fn:trim | 去除字符串前后的空格 | ${fn.trim(name)} |
其实就是一些JAVA中处理字符串的方法。
end..