实际意义: 就是在页面中从3开始,循环输出 时间
 
package com.randy.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

public class BodyTag extends BodyTagSupport {

    
   private int countNum =0; //循环显示时间的次数
   private int currentNum =1; //当前执行次数
    
  @Override
   public int doAfterBody() throws JspException {


     try {
      JspWriter out = pageContext.getOut();
      out.println( "第"+currentNum+ "次执行标签体。标签体执行完毕。
"
);
        
       if(countNum >1){
        countNum--;
        currentNum ++;
         return EVAL_BODY_TAG;
      } else{
         return SKIP_BODY;
      }
    } catch (IOException e) {
      e.printStackTrace();
       return SKIP_BODY;
    }
  }

  @Override
   public int doEndTag() throws JspException {
    
     try {
      JspWriter out = pageContext.getOut();
      bodyContent.writeOut(bodyContent.getEnclosingWriter()); //输出标签体的内容
      out.println( "标签结束了");
    } catch (IOException e) {
      e.printStackTrace();
    }
     return EVAL_PAGE;
  }

  @Override
   public void doInitBody() throws JspException {

    currentNum=3;
     super.doInitBody();
  }

  @Override
   public int doStartTag() throws JspException {
       try {
        JspWriter out = pageContext.getOut();
        out.println( "标签开始了:
"
);
        
         if(countNum>0){
           return EVAL_BODY_TAG;
        } else{
           return SKIP_BODY;
        }
      } catch (IOException e) {
        e.printStackTrace();
         return SKIP_BODY;
      }
    
  }

   public int getCountNum() {
     return countNum;
  }

   public void setCountNum( int countNum) {
     this.countNum = countNum;
     this.currentNum =1;
  }

    
    
}
 
 
tld
  
    含有标签体
    bodyTag
    class>com.randy.tag.BodyTagclass>
    JSP
    
    
      countNum
       true
       true
    

  
 
注意JSP 的大写。 书上写的是小写,不对。
 
"6">
  <%= new java.util.Date() %>