熟悉标签库的朋友进来帮忙看一下,急
我用标签库写了一个简单的循环标签,
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class LoopTag extends BodyTagSupport{
private int maxCount = 0;
private int currentCount = 0;
public void setCount(int count){
this.maxCount = count;
}
public int doStartTag(){
if(currentCount < maxCount){
return EVAL_BODY_BUFFERED;
}else
return SKIP_BODY;
}
public int doAfterBody() throws JspException{
currentCount++ ;
if(currentCount < maxCount){
return EVAL_BODY_BUFFERED;
}else{
return SKIP_BODY;
}
}
public int doEndTag() throws JspException{
try{
if(bodyContent != null){
bodyContent.writeOut(bodyContent.getEnclosingWriter());
}
}catch(java.io.IOException ioe){
throw new JspException("IO Error" + ioe.getMessage());
}
return EVAL_PAGE;
}
public void release(){
super.release();
currentCount = 0;
}
}
调用标签库的jsp如下:
<%@ page contentType="text/html; charset=GBK"%>
<%@ taglib uri="/bad" prefix="bad"%>
<html>
<head>
<title>
test
</title>
</head>
<body bgcolor="#ffffff">
<table>
<% int i = 0 ;%>
<bad:loop count="5">
<tr>
<bad:loop count="6">
<td bgcolor=#ccccff><%= i++ %></td>
</bad:loop>
</tr>
</bad:loop>
</table>
</body>
</html>
可是打印出来的结果却是:
0 1 2 3 4 5
0 1 2 3 4 5
0 1 2 3 4 5
0 1 2 3 4 5
0 1 2 3 4 5
重第2行开始就没有递增了,请熟悉的朋友解答一下!!!