[原]EL函数的使用

[标题]:EL函数的使用
[时间]:2009-4-3
[摘要]:简单的EL函数示例。
[关键字]:EL,function,tld,jsp,jstl,标签
[平台]:Tomcat6
[作者]:Winty (wintys@gmail.com)

[正文]:
Step1:
    编写所需要的类,将编译生成的el.ELFunction复制到WEB-INF/中。
package el;

public class ELFunction{
    public static String toUpper(String str){
        return str.toUpperCase();
    }
}
注意,用于EL中的函数需定义为static,不然会出错。

Step2:
        在WEB-INF/tlds中添加el.tld,内容如下 :
<?xml version = '1.0' encoding = 'GBK'?>
<taglib xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee">
  <tlib-version>1.0</tlib-version>
  <short-name>fc</short-name>
  <uri>http://wintys/el</uri>
  <function>
     <name>toUpper</name>
     <function-class>el.ELFunction</function-class>
     <function-signature>
        java.lang.String toUpper(java.lang.String)
     </function-signature>
  </function>
</taglib>
Step3:
    在WEB-INF/web.xml中添加:
<taglib>
    <taglib-uri>http://wintys/el</taglib-uri>
    <taglib-location>/WEB-INF/tlds/el.tld</taglib-location>
</taglib>
Step4:
    编写测试页面ELFunction.jsp:
<%@page contentType="text/html;charset=GBK" %>
<%@taglib uri="http://wintys/el" prefix="myfun" %>
EL Function:<br />
${myfun:toUpper("abcde")}
重启Tomcat后运行ELFunction.jsp即可得到结果。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
11.函数函数说明 使用举例 12.fn:contains 判定字符串是否包含另外一个字符串 <c:if test="${fn:contains(name, searchString)}"> 13.fn:containsIgnoreCase 判定字符串是否包含另外一个字符串(大小写无关) <c:if test="${fn:containsIgnoreCase(name, searchString)}"> 14.fn:endsWith 判定字符串是否以另外字符串结束 <c:if test="${fn:endsWith(filename, ".txt")}"> 15.fn:escapeXml 把一些字符转成XML表示,例如 <字符应该转为< ${fn:escapeXml(param:info)} 16.fn:indexOf 子字符串在母字符串中出现的位置 ${fn:indexOf(name, "-")} 17.fn:join 将数组中的数据联合成一个新字符串,并使用指定字符格开 ${fn:join(array, ";")} 18.fn:length 获取字符串的长度,或者数组的大小 ${fn:length(shoppingCart.products)} 19.fn:replace 替换字符串中指定的字符 ${fn:replace(text, "-", "?")} 20.fn:split 把字符串按照指定字符切分 ${fn:split(customerNames, ";")} 21.fn:startsWith 判定字符串是否以某个子串开始 <c:if test="${fn:startsWith(product.id, "100-")}"> 22.fn:substring 获取子串 ${fn:substring(zip, 6, -1)} 23.fn:substringAfter 获取从某个字符所在位置开始的子串 24.${fn:substringAfter(zip, "-")} 25.fn:substringBefore 获取从开始到某个字符所在位置的子串 ${fn:substringBefore(zip, "-")} 26.fn:toLowerCase 转为小写 ${fn.toLowerCase(product.name)} 27.fn:toUpperCase 转为大写字符 ${fn.UpperCase(product.name)} 28.fn:trim 去除字符串前后的空格 ${fn.trim(name)}

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值