日期:2014-05-16  浏览次数:20473 次

freemarker 中引用jsp标签 输出当前日期

<#global fundtradeTag=JspTaglibs["/WEB-INF/tld/fundTrade.tld"]>

<td>下单日期:</td>
??????? ??? <td><@fundtradeTag.currDate/></td>

?

下面是文件

///WEB-INF/tld/fundTrade.tld

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib
??????? PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
??????? "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
??? <tlib-version>1.3</tlib-version>
??? <jsp-version>1.2</jsp-version>
??? <short-name>currDate</short-name>
??????
??? <tag>
??????? <name>currDate</name>
??????? <tag-class>com.howbuy.fundtrade.web.tag.CurrDateTag</tag-class>
??????? <body-content>JSP</body-content>
??? </tag>
???
</taglib>

?

? /**
??? ?* 标签类
??? ?*/

public class CurrDateTag extends BodyTagSupport{
??? /**
??? ?*
??? ?*/
??? private static final long serialVersionUID = 1L;

??? public int doStartTag() throws JspException {

???????
??????? return Tag.EVAL_BODY_INCLUDE;
??? }
??? protected String renderDateElement() {
??? ??? return MfDate.today().toString(MfDate.defaultDatePattern);
??? }
??? public int doEndTag() throws JspException {
??????? try {
??????????? JspWriter out = pageContext.getOut();
??????????? String s = renderDateElement();
??????????? out.print(s);
??????????
???????????
??????? } catch (Exception e) {
??????? }
??????? return (EVAL_PAGE);
??? }
}

?