满足条件跳出循环,该如何做呢?谢谢

myepoch 2008-12-10 11:51:38
在逻辑标记库中定义了<logic:iterate>

请问当用这个标签的时候,当满足条件我将跳出循环,该如何做呢。

比如当ID=20我跳出这个循环

int intArray[] = new int[]
{ 0, 10, 20, 30, 40 };
pageContext.setAttribute("intArray", intArray);
...全文
339 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
lanzhengwu 2008-12-10
  • 打赏
  • 举报
回复
顶上 ..
ivan_xu 2008-12-10
  • 打赏
  • 举报
回复

if(id == 20) {
break;
}
petrarca 2008-12-10
  • 打赏
  • 举报
回复
* @throws JspException if a JSP exception has occurred
*/
public int doAfterBody() throws JspException {
// Render the output from this iteration to the output stream
if (bodyContent != null) {
TagUtils.getInstance().writePrevious(pageContext,
bodyContent.getString());
bodyContent.clearBody();
}

// Decide whether to iterate or quit
if ((lengthValue > 0) && (lengthCount >= lengthValue)) {
return (SKIP_BODY);
}

// Add method you wish to do.
mehod(){
return EVAL_PAGE;
}

if (iterator.hasNext()) {
Object element = iterator.next();

if (element == null) {
pageContext.removeAttribute(id);
} else {
pageContext.setAttribute(id, element);
}

lengthCount++;

if (indexId != null) {
pageContext.setAttribute(indexId, new Integer(getIndex()));
}

return (EVAL_BODY_TAG);
} else {
return (SKIP_BODY);
}
}
petrarca 2008-12-10
  • 打赏
  • 举报
回复
* @throws JspException if a JSP exception has occurred
*/
public int doAfterBody() throws JspException {
// Render the output from this iteration to the output stream
if (bodyContent != null) {
TagUtils.getInstance().writePrevious(pageContext,
bodyContent.getString());
bodyContent.clearBody();
}

// Decide whether to iterate or quit
if ((lengthValue > 0) && (lengthCount >= lengthValue)) {
return (SKIP_BODY);
}

// Add method you wish to do.
mehod(){
return EVAL_PAGE;
}

if (iterator.hasNext()) {
Object element = iterator.next();

if (element == null) {
pageContext.removeAttribute(id);
} else {
pageContext.setAttribute(id, element);
}

lengthCount++;

if (indexId != null) {
pageContext.setAttribute(indexId, new Integer(getIndex()));
}

return (EVAL_BODY_TAG);
} else {
return (SKIP_BODY);
}
}
petrarca 2008-12-10
  • 打赏
  • 举报
回复
修改原代码。
baijunxiang 2008-12-10
  • 打赏
  • 举报
回复
<logic:iterate >不支持break,continue功能
java_qingchong 2008-12-10
  • 打赏
  • 举报
回复
可以加上length和offset属性控制循环
<logic:iterate length="2" offset="1"></logic:iterate>

length循环的个数
offset从第几个开始循环
myepoch 2008-12-10
  • 打赏
  • 举报
回复
我的意思是<logic:iterate> 标签中跳出循环

81,114

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧