码迷,mamicode.com
首页 > 其他好文 > 详细

开发带属性的标签

时间:2014-07-30 03:16:32      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   java   os   io   

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

开发带属性的标签

标签:des   style   blog   http   color   java   os   io   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!