六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 35|回复: 0

jstl的forEach使用和jstl变量实现自增

[复制链接]

升级  73.33%

46

主题

46

主题

46

主题

秀才

Rank: 2

积分
160
 楼主| 发表于 2013-1-27 05:36:05 | 显示全部楼层 |阅读模式
<c:forEach items="${reallyChooseSubjectList}" var="reallyChooseSubject">       <tr>   <td width="20px;">(<%=i %>) </td><td>${reallyChooseSubject.name}</td>   <td>   <input type="hidden" name="subjectId<%=i %>" id="subjectId<%=i %>" value="${reallyChooseSubject.id }">   </td>   </tr>   <tr>   <td width="20px;"><td><input type="radio" name="answer<%=i %>" value="A" />A.${reallyChooseSubject.answer_A}</td><td></td>   </tr>   <tr>   <td width="20px;"><td><input type="radio" name="answer<%=i %>" value="B" />B.${reallyChooseSubject.answer_B}</td><td></td>   </tr>   <tr>   <td width="20px;"><td>   <c:if test="${reallyChooseSubject.answer_C != ''}" scope="page">   <input type="radio" name="answer<%=i %>"  value="C" />C.${reallyChooseSubject.answer_C}   </c:if>   </td><td></td>   </tr>   <tr>   <td width="20px;"><td>   <c:if test="${reallyChooseSubject.answer_D != ''}" scope="page">   <input type="radio" name="answer<%=i %>"  value="D" />D.${reallyChooseSubject.answer_D}   </c:if>   </td><td></td>   </tr>   <tr><%i++; %></tr>   </c:forEach>

在循环中变量自增:
<%@ page contentType="text/html;charset=gbk" %><%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %><html><head><title>x</title><meta http-equiv="Content-Type" content="text/html;charset=gbk"></head><body><c:set var="index" value="0" /><c:forEach var="x" begin="1" end="9" step="1"><c:set var="index" value="${index+1}" />index:${index}x:${x }<br></c:forEach><br></body></html>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表