`

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

    博客分类:
  • jsp
阅读更多
<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>
分享到:
评论

相关推荐

    第8章 JSTL.ppt

    forEach标签可以将集合中的成员遍历一遍,通过items属性指定一个集合,var属性指明集合中的一个成员,可以通过var属性指定的变量来访问集合中的成员。 实例 爱好:&lt;c:forEach items="${paramValues.Habit}" var=...

    JSP实例编程100例

    12、&lt;c:forEach&gt; begin、end和step的用法 13 、 &lt;c:forEach&gt; 循环 14、&lt;c:forEach&gt; varStatus 的四种属性 15、&lt;c:forEach&gt; 的用法 16、从客户端传送数据至服务端 17、使用Unicode转义字符 18、使用朝鲜语字符集 19、...

    EL表达式 (详解)

    2--EL表达式可操作常量 变量 和隐式对象. 最常用的 隐式对象有${param}和${paramValues}. ${param}表示返回请求参数中单个字符串的值. ${paramValues}表示返回请求参数的一组 值.pageScope表示页面范围的变量....

    JAP编程学习100例

    12、&lt;c:forEach&gt; begin、end和step的用法 13 、 &lt;c:forEach&gt; 循环 14、&lt;c:forEach&gt; varStatus 的四种属性 15、&lt;c:forEach&gt; 的用法 16、从客户端传送数据至服务端 17、使用Unicode转义字符 18、使用朝鲜语字符集 19、...

    在JSTL EL中处理java.util.Map,及嵌套List的情况

    当forEach 的items属性中的表达式的值是java.util.Map时,则var中命名的变量的类型就是 java.util.Map.Entry。这时var=entry的话,用表达式${entry.key}取得键名。 用表达${entry.value}得到每个entry的值。这是...

    一个简单的spring mvc实例.docx

    在 Spring MVC 中, jsp 文件中尽量不要有 Java 代码, 只有 HTML 代码和"迭代(forEach)"与"判断(if)"两个jstl标签. jsp 文件只作为渲染(或称为视图 View)模板使用. 好了, 我们开始吧. 首先我们需要一个放在 WEB-INF ...

    Spring MVC 入门实例

    在 Spring MVC 中, jsp 文件中尽量不要有 Java 代码, 只有 HTML 代码和"迭代(forEach)"与"判断(if)"两个jstl标签. jsp 文件只作为渲染(或称为视图 View)模板使用. 好了, 我们开始吧. 首先我们需要一个放在 WEB-INF...

    Java学习笔记-个人整理的

    {1.8.1}自增运算}{28}{subsection.1.8.1} {1.8.1.1}Postincrement}{28}{subsubsection.1.8.1.1} {1.8.1.2}Preincrement}{28}{subsubsection.1.8.1.2} {1.8.1.3}复合赋值运算}{28}{subsubsection.1.8.1.3} {...

Global site tag (gtag.js) - Google Analytics