熟悉标签库的朋友进来帮忙看一下,急

MopeLeo MopeLeo 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我用标签库写了一个简单的循环标签,
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行开始就没有递增了,请熟悉的朋友解答一下!!!
...全文
评论 34
收藏 已收藏
分享
返回顶部
MopeLeo
Web 开发 81,108 成员 341,721 内容