zoukankan      html  css  js  c++  java
  • 创建自定义的EL function(Creating a custom EL function)

    测试环境: tomcat7,jdk1.7

    1.First make a class with a static method like so:

    package your.package;
    
    public class Functions {
    
           public static String hello(String name) {
             return "Hiya, " + name + ".";
           }
    
    }

    2. Then make a file called mytaglib.tld in WEB-INF/tags/:

    <?xml version="1.0" encoding="ISO-8859-1" ?>
        <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/javaee/web-jsptaglibrary_2_1.xsd" 
          version="2.1"> 
    
          <tlib-version>1.0</tlib-version>
          <uri>http://www.your.url/tablib_name</uri>
    
          <function>
              <name>hello</name>
              <function-class>your.package.Functions</function-class>
              <function-signature>java.lang.String hello(java.lang.String)</function-signature>
    
          </function>  
    
        </taglib>     

    3. The uri would be used if we were accessing this directly, but instead we’ll be accessing the url from the web.xml below:

     <web-app 
            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-app_2_4.xsd"
            version="2.4">
    
            ...
    
           <jsp-config>
           <taglib>
             <taglib-uri>
               http://some.thing/mine
             </taglib-uri>
             <taglib-location>
               /WEB-INF/tags/mytaglib.tld
             </taglib-location>
           </taglib> 
           </jsp-config>
    
           ...
    
         </web-app>

    4. Note we’re pointing to the mytaglib.tld file just created. And taglib-uri is how we’ll refer to it in the JSP:

        <%@ taglib uri="http://some.thing/mine" prefix="a" %> 
    
        ${a:hello("Aaron")}
  • 相关阅读:
    20161203
    20161201
    20161128课堂笔记
    数组排序 (选择排序、冒泡排序、插入排序、希尔排序)
    编一个多用户登陆程序
    20161115课堂笔记
    20161114课堂笔记
    20161111课堂笔记
    面试常见问题
    java 基础第一周
  • 原文地址:https://www.cnblogs.com/david-rui/p/4542860.html
Copyright © 2011-2022 走看看