例如对于以下 EL 表达式:
<c:set value=’${ fn: split (“”,”.”)}’ var=”strs”/>
<c:forEach var=”token” item=”${strs}”>
${token}<br/>
</c:forEach>
其输出结果为:
mywebsite
org
再例如对于以下代码:
<c:set value=’${ fn: split (“”,”-”)}’ var=”strs”/>
${strs[0]}
其输出结果为:
18.11 fn:join 函数
fn:join 函数用于将源字符串数组中的所有字符串连接为一个字符串,其语法为:
fn:join(String source[],String separator) ----String
以上 source 参数指定源字符串数组, separator 参数指定用于连接源字符串数组中的各个字符串的分隔符,返回类型为 String 。
例如对于以下代码:
<%
String strs[] = {“”,”mywebsite”,”org”};
%>
<c:set value=”<%=strs%>” var=”strs”/>
${fn:join(strs,”.”)}
其输出结果为:
mywebsite. org
18.12 fn:toLowerCase 函数
fn:toLowerCase 函数用于将源字符串中的所有字符改为小写,其语法为:
fn:toLowerCase(String source) -----String
以上 source 参数指定源字符串,返回类型为 String 。
例如对于以下 EL 表达式:
fn:toLowerCase(“TomCat”)
其输出结果为:
tomcat
18.13 fn:toUpperCase 函数
fn: toUpperCase 函数用于将源字符串中的所有字符改为大写,其语法为:
fn: toUpperCase (String source) -----String
以上 source 参数指定源字符串,返回类型为 String 。
例如对于以下 EL 表达式:
fn: toUpperCase (“TomCat”)
其输出结果为:
TOMCAT
18.14 fn:trim 函数
fn:trim 函数用于将源字符串中的开头和末尾的空格删除,其语法为:
fn:trim(String source) ----String
以上 source 参数指定源字符串,返回类型为 String 。
例如对于以下 EL 表达式:
fn:trim(“ Tomcat ”)
以上 EL 表达式的值为“ Tomcat ”。
18.15 fn:escapeXml 函数
fn:escapeXml 函数用于将源字符串中的字符“ < ”、“ > ”、“ ” ”和“ & ”等转换为转义字符,本书第 1 章的 1.2 节( HTML 简介)介绍了转义字符的概念。 fn:escapeXml 函数的行为与 <c:out> 标签的 escapeXml 属性为 true 时的转换行为相同, fn:escapeXml 函数的语法为:
fn:escapeXml(String source) ----String
以上 source 参数指定源字符串,返回类型为 String 。
例程 18-1 的 out.jsp 演示了 fn:escapeXml 函数的用法。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-32905-19.html
期待小王子
加油哈
直接动动炮肯定不妥