⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bodytagexample.java

📁 JSP中简单标记与经典标记设计示例代码
💻 JAVA
字号:
package com.jspdev.experiment;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.Writer;
import java.io.IOException;
public class BodyTagExample extends BodyTagSupport {
	String username;		//对应于自定义标签的userName属性
	int count;			//对应于自定义标签的count属性
	public BodyTagExample() {
		super();
	}	
	/**
	 *设置userName属性。这个方法由容器自动调用。
	 */
	public void setUserName(String user) {
		this.UserName=user;
	}
/**
	 *设置count属性。这个方法由容器自动调用。
	 */
	public void setCount(int c) {
		this.count=c;
	}
	/**
	 *覆盖doStartTag方法
	 */
	 public int doStartTag() throws JspTagException {   
	     System.out.println("doStartTag");
	     if(count>0) { 
	         return EVAL_BODY_TAG;
	     } 
	     else { 
	          return SKIP_BODY;
	     } 
    }    
    /**
     *覆盖doAfterBody方法
     */
    public int doAfterBody() throws JspTagException 
    { 
        System.out.println("doAfterBody"+count);
        if(count-- >=1) {
				try {
					JspWriter out=bodyContent.getEnclosingWriter();
					out.println(bodyContent.getString() + username);
					out.println("<br>");
					//Clear for next evaluation
					bodyContent.clearBody();
				}
				catch(IOException ioe) {
					System.out.println("Error in RepeatTag: " + ioe);
				}
        		return EVAL_BODY_TAG; 
         }  
         else
         { 
            return SKIP_BODY; 
         } 
    }    
   /**
    *覆盖doEndTag方法
    */
    public int doEndTag() throws JspTagException {
        System.out.println("doEndTag");
        return EVAL_PAGE;  
    }
    
    public void doInitBody() throws JspTagException{
      System.out.println("doInitBody");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -