[标题]: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即可得到结果。
	
posted on 2009-04-03 21:29 
天堂露珠 阅读(1378) 
评论(0)  编辑  收藏  所属分类: 
Java