WEB-INF下新建xxx.tld文件
1.0 1.0 tiles http://jakarta.apache.org/struts/tags-tiles date com.clouds.util.tag.DateTag jsp value true true type false true delivery com.clouds.util.tag.DeliveryTag jsp value true true product com.clouds.util.tag.ProductsTag jsp value true true
新建对应的类:
/**
* @Title: DateTag.java* @Package com.clouds.util* @Description: TODO(用一句话描述该文件做什么)* @author 周张豹* @date 2012-9-11 下午05:20:46* @version V1.0 */package com.clouds.util.tag;import java.io.IOException;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;import javax.servlet.jsp.JspException;import javax.servlet.jsp.tagext.TagSupport;/** * @ClassName: DateTag * @Description: TODO(这里用一句话描述这个类的作用) * @author 周张豹 * @date 2012-9-11 下午05:20:46 * */public class DateTag extends TagSupport { private static final long serialVersionUID = 6464168398214506236L; private String value; private String type; @Override public int doStartTag() throws JspException { String vv = ""+value; if (value != null && !"".equals(value)) { Long a = Long.valueOf(value); Long aa = (Long) a * 1000; Date b = new Date(aa); if (type == null || "".equals(type)) { type = "yyyy-MM-dd HH:MM:ss"; } SimpleDateFormat sdf= new SimpleDateFormat(type); String date = sdf.format(b); try { pageContext.getOut().write(date+""); } catch (IOException e) { e.printStackTrace(); } } return super.doStartTag(); } public static void main(String[] args) throws JspException { DateTag tag = new DateTag(); tag.doStartTag(); } public void setValue(String value) { this.value = value; } /** * @return 获取 type 的值 */ public String getType() { return type; } /** * @param 设置 type 的值 */ public void setType(String type) { this.type = type; }}
页面上调用如下: