首页 > 代码库 > jstl变量实现自增
jstl变量实现自增
Java代码
- <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=http://www.mamicode.com/"${reallyChooseSubject.id }">
- </td>
- </tr>
- <tr>
- <td width="20px;"><td><input type="radio" name="answer<%=i %>" value=http://www.mamicode.com/"A" />A.${reallyChooseSubject.answer_A}</td><td></td>
- </tr>
- <tr>
- <td width="20px;"><td><input type="radio" name="answer<%=i %>" value=http://www.mamicode.com/"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=http://www.mamicode.com/"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=http://www.mamicode.com/"D" />D.${reallyChooseSubject.answer_D}
- </c:if>
- </td><td></td>
- </tr>
- <tr><%i++; %></tr>
- </c:forEach>
在循环中变量自增:
Java代码
- <%@ 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=http://www.mamicode.com/"0" />
- <c:forEach var="x" begin="1" end="9" step="1">
- <c:set var="index" value=http://www.mamicode.com/"${index+1}" />
- index:${index}
- x:${x }
- <br>
- </c:forEach>
- <br>
- </body>
- </html>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。