el自定义函数库

举一个编码问题的例子:

/**

 * 自定义El函数库

 *@author Administrator

 *

 */

public class FunctionsEl {

       publicstatic String decode(String str) throws UnsupportedEncodingException{

              if(StringUtils.isNotBlank(str)){

                     returnURLDecoder.decode(str,"utf-8");

              }

              return"";

       }

}

写一个tld文件

<?xml version="1.0"encoding="UTF-8" ?>

<taglibxmlns="http://java.sun.com/xml/ns/j2ee"

 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

 xsi:schemaLocation="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"

 version="2.0">

 <description>MYJSTL 1.0 functions library</description>

 <display-name>MYJSTL functions</display-name>

 <tlib-version>1.0</tlib-version>

 <short-name>myfn</short-name>

 <uri>http://www.xxx.cn/jsp/jstl/functions</uri>

 <function>

   <name>decode</name>

    <!--此处是定义类的路径-->

   <function-class>cn.xxx.crm.functions.FunctionsEl</function-class>

     <!--此处是定义类的返回值类型和传入参数类型-->

   <function-signature>java.lang.String decode(java.lang.String)</function-signature>

 </function>

</taglib>

在jsp页面中的使用:

<!--首先要引入-->

<%@ tagliburi="http://www.xxx.cn/jsp/jstl/functions" prefix="myfn"%>

${myfn:decode(string)}搞定

原文地址:https://www.cnblogs.com/jqyp/p/1816501.html