jstl 自定义标签

<!--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">  
       
  <tlib-version>1.0</tlib-version>  
  <short-name>demo</short-name>  
  <uri>/WEB-INF/tags/tld/functionTag.tld</uri> 
  <!--方法 --> 
   <function>  
    <name>demo</name>  
    <function-class>com.demo.utils.functionTag.JstlTagUtil</function-class>  
    <function-signature>java.lang.String demo(java.lang.String)</function-signature>  
  </function> 
</taglib>
package com.demo.core.utils.functionTag;public class JstlTagUtil {    
//demo对应的类和方法
    public static String demo(String id){return id;
    }
}
<!--web.xml文件添加-->
<jsp-config>
    <taglib>
      <taglib-uri>/tags/tld/functionTag</taglib-uri>
      <taglib-location>/WEB-INF/tags/tld/functionTag.tld</taglib-location>
    </taglib>
</jsp-config>
<!--jsp文件引入-->
<%@ taglib prefix="demo"  uri="/WEB-INF/tags/tld/functionTag.tld"%><br /><br /><p>${demo:demo('id')}</p>

相关推荐