?? mytagforeach.java
字號:
package cn.tag;
import java.io.IOException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;
public class MytagforEach extends BodyTagSupport{
private static final long serialVersionUID = 1L;
protected String value = null; //對應forEach標簽中的value屬性
protected int count = 0; //對應forEach標簽中的count屬性,默認為0
public MytagforEach(){
super();
}
public void setValue(String value){ //設置value屬性值,容器會自動調用
this.value = value;
}
public String getValue(){
return value;
}
public void setCount(int count){ //設置count屬性值,容器會自動調用
this.count = count;
}
public int getCount(){
return count;
}
/***** 覆蓋父類實現的doStartTag()方法 *****/
public int doStartTag() throws JspTagException{
if(count > 0){ //如果循環沒有結束
return EVAL_BODY_INCLUDE; //表示繼續進行體的處理
}
else{ //循環結束
return SKIP_BODY;
}
}
/***** 覆蓋父類實現的doEndTag()方法 *****/
public int doEndTag() throws JspTagException{
return EVAL_PAGE;
}
/***** 覆蓋父類實現的doAfterBody()方法 *****/
public int doAfterBody() throws JspTagException{
if(count-- >= 1){ //循環一次,count減一,如果count還大于1,執行
try{
JspWriter out = bodyContent.getEnclosingWriter();
out.println(bodyContent.getString()+value);
out.println("<br>");
bodyContent.clearBody(); //清空bodyContent對象中的內容
}catch(IOException e){
System.out.println("Error in RepeatTag: "+e);
}
return EVAL_BODY_INCLUDE;
}else{
return SKIP_BODY;
}
}
/***** 覆蓋父類實現的doInitBody()方法 *****/
public void doInitBody() throws JspTagException{
//這里不作任何初始化
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -