自定义EL函数
来源:互联网 发布:2016流行网络词语 编辑:程序博客网 时间:2024/06/07 07:16
一、利用EL表达式调用普通Java类中的静态方法
1、编写一个java类,并编写一个静态方法,如下所示:
public class ElDemo {
//静态方法:将小写转换为大写
public static String convert(String str){
return str.toUpperCase();
}
}
它的功能就是将参数变为大写
2、创建一个标签描述文件(tld)文件,其就是一个xml文件,一般放在WEB-INF下,创建的文件如下:
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
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">
<description>我的tld</description>
<display-name>mytld</display-name>
<tlib-version>1.0</tlib-version>
<short-name>mm</short-name>
<uri>http://www.itcast.cn/tld</uri>
<function><!--定义一个函数-->
<name>convert</name><!--函数名称,以便在jsp中调用-->
<function-class>cn.itcast.el.ElDemo</function-class><!--指定是哪个类中的函数,类名用全名-->
<function-signature>
java.lang.String convert(java.lang.String)<!--指定方法的签名。返回值类型和参数类型要用全名-->
</function-signature>
</function>
</taglib>
3、在web.xml中注册该tld文件
<jsp-config>
<taglib>
<taglib-uri>http://www.itcast.cn/tld</taglib-uri><!--与tld中uri一致就可-->
<taglib-location>/WEB-INF/tld/mytld.tld</taglib-location><!--tld所在的位置-->
</taglib>
</jsp-config>
4、在JSP中使用该函数
先利用taglib指令引入该tld
<%@ taglib uri="http://www.itcast.cn/tld" prefix="mm"%>
用一下代码来调用
1、编写一个java类,并编写一个静态方法,如下所示:
public class ElDemo {
//静态方法:将小写转换为大写
public static String convert(String str){
return str.toUpperCase();
}
}
它的功能就是将参数变为大写
2、创建一个标签描述文件(tld)文件,其就是一个xml文件,一般放在WEB-INF下,创建的文件如下:
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
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">
<description>我的tld</description>
<display-name>mytld</display-name>
<tlib-version>1.0</tlib-version>
<short-name>mm</short-name>
<uri>http://www.itcast.cn/tld</uri>
<function><!--定义一个函数-->
<name>convert</name><!--函数名称,以便在jsp中调用-->
<function-class>cn.itcast.el.ElDemo</function-class><!--指定是哪个类中的函数,类名用全名-->
<function-signature>
java.lang.String convert(java.lang.String)<!--指定方法的签名。返回值类型和参数类型要用全名-->
</function-signature>
</function>
</taglib>
3、在web.xml中注册该tld文件
<jsp-config>
<taglib>
<taglib-uri>http://www.itcast.cn/tld</taglib-uri><!--与tld中uri一致就可-->
<taglib-location>/WEB-INF/tld/mytld.tld</taglib-location><!--tld所在的位置-->
</taglib>
</jsp-config>
4、在JSP中使用该函数
先利用taglib指令引入该tld
<%@ taglib uri="http://www.itcast.cn/tld" prefix="mm"%>
用一下代码来调用
${mm:convert("abcdefg")}------------------->输出ABCDEFG
源文件下载地址:http://download.csdn.net/detail/afgasdg/3813594
- 如何自定义EL函数
- EL自定义函数
- el自定义函数
- JSP自定义EL函数
- EL自定义函数
- 自定义EL函数
- EL表达式-自定义函数
- EL表达式-自定义函数
- 自定义el函数
- EL自定义函数
- 自定义EL函数
- EL自定义函数
- EL自定义函数
- 自定义EL函数
- 自定义EL函数
- EL表达式-自定义函数
- 自定义EL函数
- 自定义el函数
- python算法分析 笔记 ——打印全排列
- 前辈大公司的面试,重点是他推荐我们应该看得那些书
- 使用NPOI导入导出标准Excel
- 迅雷精简版1.4.3.156去BT文件自动关联
- Hadoop 0.23编译
- 自定义EL函数
- 炮兵阵地 POJ1185
- [STM32入门]---在STM3210EVB上运行uc-OS(IAR平台
- objective-c 转发
- 别人推荐的一些计算机行业的书
- 【整理】使得Eclipse同时支持Java和CDT
- magento评论,评分信息,sql语句
- linux命令常用
- magento模板