首页 > 其他 > 详细

开发带属性的标签

时间:2014-07-30 03:16:33      阅读:406      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 1 package cn.itcast.web.tag;
 2 
 3 import java.io.IOException;
 4 import java.io.StringWriter;
 5 import java.util.Date;
 6 
 7 import javax.servlet.jsp.JspException;
 8 import javax.servlet.jsp.tagext.JspFragment;
 9 import javax.servlet.jsp.tagext.SimpleTagSupport;
10 
11 //开发带属性的内容
12 public class SimpleTagDemo1 extends SimpleTagSupport {
13     
14     private int count;
15     private Date date;
16     
17     public void setDate(Date date) {
18         this.date = date;
19     }
20 
21 
22     public void setCount(int count){
23         this.count=count;
24     }
25     
26     
27     @Override
28     public void doTag() throws JspException, IOException {
29         JspFragment jf = this.getJspBody();
30         this.getJspContext().getOut().write(date.toLocaleString()+"<br/>");
31         for (int i = 0; i < count; i++) {
32             jf.invoke(null);
33         }
34     }
35 
36     
37 
38 }
SimpleTagDemo1
bubuko.com,布布扣
 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 
 3 
 4 <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
 5     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 6     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
 7     version="2.0">
 8     <description>A tag library exercising SimpleTag handlers.</description>
 9     <tlib-version>1.0</tlib-version>
10     <short-name>itcast</short-name>
11     <uri>/itcast</uri>
12     
13     <tag>
14         <name>SimpleTagDemo1</name>
15         <tag-class>cn.itcast.web.tag.SimpleTagDemo1</tag-class>
16         <body-content>scriptless</body-content>
17         
18         <attribute>
19             <name>count</name>
20             <required>true</required>
21             <rtexprvalue>true</rtexprvalue>
22         </attribute>
23         <attribute>
24             <name>date</name>
25             <required>true</required>
26             <rtexprvalue>true</rtexprvalue>
27         </attribute>
28     </tag>
29     
30    
31   
32   </taglib>
itcast.tld
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="/itcast" prefix="itcast" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>开发带属性的内容</title>
  
  </head>
  
  <body>
  <itcast:SimpleTagDemo1 count="9" date="<%=new Date() %>">
  	Zero<br/>
  </itcast:SimpleTagDemo1>
   	
  </body>
</html>

  

开发带属性的标签,布布扣,bubuko.com

开发带属性的标签

原文:http://www.cnblogs.com/aineko/p/3876809.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!