1、在web.xml文件里配
<description>there are custom tags of class3g</description> <tlib-version>1.0</tlib-version> <short-name>Date</short-name> <uri>http://www.Date.com</uri> <tag> <description>demo</description> <name>dateTag</name> <tag-class>cn.csdn.web.tag.DateTag</tag-class> <body-content>scriptless</body-content> </tag>
2、在jsp页面里写上
<date:dateTag>2011-10-12</date:dateTag>
3、编写一个实现tag接口的实现类
package cn.csdn.web.tag; import java.io.IOException; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.BodyContent; import javax.servlet.jsp.tagext.BodyTagSupport; public class DateTag extends BodyTagSupport { @Override public int doStartTag() throws JspException { return super.doStartTag(); } @Override public int doEndTag() throws JspException { BodyContent bc = this.getBodyContent(); String content = bc.getString(); String[] str = content.split("-"); String date[] = { "年", "月", "日" }; JspWriter out = this.pageContext.getOut(); for (int i = 0; i < str.length; i++) { try { out.write(date[i] + ":"); out.write(str[i]); out.write("<br>"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return super.doEndTag(); } }