日期:2014-05-16  浏览次数:20317 次

JSTL两列显示

在jsp页面通过foreach遍历的时候需要两个记录放在一行显示即

<tr>
<td>记录1</td>
<td>记录2</td>
</tr>

?那么jstl中如下实现:

						<c:forEach var="item" items="${persons}" varStatus="status">
							<c:if test="${status.index%2==0}">
								<tr>
							</c:if>
							<td><a href="${ basePath}ar/getrelations?rowKey=${item}">${item
									}</a></td>
							<c:if test="${status.index%2!=0}">
								</tr>
							</c:if>
						</c:forEach>

?这里采用了varStatus的index属性,此类用法中最常用的属性如下:

current    当前这次迭代的(集合中的)项 
index      当前这次迭代从 0 开始的迭代索引 
count      当前这次迭代从 1 开始的迭代计数 
first      用来表明当前这轮迭代是否为第一次迭代的标志 
last       用来表明当前这轮迭代是否为最后一次迭代的标志 
?