熟悉标签库的朋友进来帮忙看一下,急
我用标签库写了一个简单的循环标签,
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行开始就没有递增了,请熟悉的朋友解答一下!!!
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行开始就没有递增了,请熟悉的朋友解答一下!!!
...全文
相关推荐
JSP 标准标签库(c标签库)
**引入C标签库** 在JSP页面中使用C标签库之前,需要首先引入JSTL库和C标签库。
Struts标签库Struts标签库Struts标签库案例
**Struts标签库介绍** - Struts标签库包括核心标签库(struts-tiles)和HTML标签库(struts-html),以及其他如逻辑标签库(struts-logic)、bean标签库
JSTL 标签库 jsp C 标签库
C标签库是JSTL中的一个核心组件,主要用于控制流操作,例如循环、条件判断等。****1.
struts2标签库struts2标签库struts2标签库
"Struts2标签库详解"Struts2标签库是Struts2框架中的一个重要组件,它提供了一系列的标签,帮助开发者快速构建Web应用程序。
struts2标签库
了解并熟练掌握Struts2标签库,不仅有助于提升开发速度,还有利于项目的长期维护。在深入学习时,可以通过实践案例来熟悉各个标签的用法,并结合官方文档和社区资源,解决实际开发中遇到的问题。


Web 开发
