自定义JSTL函数库

来源:互联网 发布:淘宝网四海认证钓具 编辑:程序博客网 时间:2024/05/20 02:26

1.新建tld文件

<?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>JSTL 1.1 functions library</description>    <display-name>JSTL functions</display-name>    <tlib-version>1.1</tlib-version>    <short-name>myfunction</short-name>    <uri>http://www.funch.xin</uri>    <function>        <name>getClassifybyId</name>        <function-class>priv.dongyukai.funch.dao.ClassifyDao</function-class>        <function-signature>java.lang.String getClassifybyId(java.lang.String)</function-signature>    </function></taglib>
  • short-name: 函数库名
  • uri: 验证地址
  • name: 函数名
  • function-class:类路径
  • function-signature: [返回值] 方法名 ([参数])

注:返回值和参数类型为全路径(如 String 为 java.lang.String),方法比须为 static!

2.引用库

<%@ taglib prefix="myfunction" uri="http://www.funch.xin"%>

3.调用函数

<c:set var="cid" value="${article.classifyId}"/>                                    ${myfunction:getClassifybyId(cid)}
原创粉丝点击