jsp 示例记录 tag file, Simple tag

 

111111Copyright22 © 汉字乱码!
<%=1+1%>
<br />
1+2 = ${1+2}

 

Simple Tag
package tags;
import java.io.IOException;
import java.util.Date;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class DateTimeTag extends SimpleTagSupport {
@Override
public void doTag() throws JspException, IOException {
Date dt
=new Date();
this.getJspContext().getOut().println("现在时间"+dt);
}
}

 

<?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.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>custom_dt</short-name>
<uri>/myCustomTags</uri>
<display-name>我的自定义</display-name>
<description>这是我的自定义标签,用于测试</description>

<tag>
<name>cus_now</name>
<tag-class>tags.DateTimeTag</tag-class>
<body-content>empty</body-content>
<description>显示现在时间
</description>
</tag>
</taglib>

 

<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib uri="/WEB-INF/CustomTag.tld" prefix="cus" %>
...
<body>  
...
    <tags:copyright></tags:copyright>
    <hr />
    <cus:cus_now/>
  </body>
</html>

posted @ 2010-11-13 18:34  庚武  Views(340)  Comments(0Edit  收藏  举报