当前位置: 移动技术网 > IT编程>网页制作>CSS > 用EL表达式调用Java的方法讲解

用EL表达式调用Java的方法讲解

2019年06月01日  | 移动技术网IT编程  | 我要评论

背景:在使用el表达式循环输出日期类型的数据,由于不知道 fmt 已经定义了日期类型的格式化方法,就自定义了一个

1.编写java静态方法 ?(class 是dateutils)

  public static string getstringdate(date date, string timeformat){
        simpledateformat formatter = new simpledateformat(timeformat);
        string datestring = formatter.format(date);
        return datestring;
    }

2.添加 .tld 配置文件(可以放在web-inf文件夹下?)


jsptaglibrary_2_0.xsd">
    jstl 1.1 functions library
    jstl functions
    1.1
    func
    /web-inf/func.tld
    
        
            converts all of the characters of a string to lower case.
        
        getstringdate
        com.util.dateutils
        java.lang.string getstringdate(java.util.date,java.lang.string)
        
            product name: ${func.getstringdate(java.util.date,java.lang.string)}
        
    

3.web.xml 根节点下添加 tld 文件的配置 (tomcat 7.0 中可用,其他环境未测试)

    
        -->
            /web-inf/func.tld-->
            /web-inf/func.tld-->
        -->
        
            /web-inf/func.tld
            /web-inf/func.tld
        
    

4.jsp引用 .tld 文件

<%@ taglib uri="/web-inf/func.tld" prefix="func"%>

5.调用自定义方法

${func:getstringdate(data.createdate, "yyyy-mm-dd hh-mm-ss")}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网