背景:在使用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")}
如对本文有疑问, 点击进行留言回复!!
荐 微信小程序动态评分展示/五角星展示/半颗星展示/自定义长度展示
深入理解CSS background-blend-mode的作用机制
网友评论