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 sys</display-name>
<tlib-version>1.1</tlib-version>
<short-name>fns</short-name>
<uri>http://java.sun.com/jsp/jstl/functionss</uri>
<function>
<description>获取当前日期</description>
<name>getDate</name>
<function-class>cn.ymcd.erim.common.utils.DateUtils</function-class>
<function-signature>java.lang.String getDate(java.lang.String)</function-signature>
<example>${fns:getDate(pattern)}</example>
</function>
</taglib>
DateUtils.java
package cn.ymcd.erim.common.utils;
import java.util.Date;
import org.apache.commons.lang3.time.DateFormatUtils;
import cn.ymcd.erim.punish.punish.dao.UserDao;
import cn.ymcd.erim.common.utils.SpringContextHolder;
import cn.ymcd.erim.punish.punish.entity.User;
public class Utils {
//获得dao层的对象
private static UserDao dao= SpringContextHolder.getBean(UserDao.class);
/**
* 得到当前日期字符串 格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E"
*/
public static String getDate(String pattern) {
return DateFormatUtils.format(new Date(), pattern);
}
/**
* 得到一个数组对象
*/
public static List<User> findList() {
return dao.findList();
}
}
jsp页面
<input type="text" value="${fns:getDate("yyyy-MM-dd")}"/>
<form:select path="value" id="value" class="input-medium" cssStyle="width: 35%">
<form:option value="" label=""/>
<form:options items="${fns:getList()}" itemLabel="label" itemValue="value"
htmlEscape="false"/>
</form:select>