如何在jsp页面 实现ArrayList结果集循环成两行两列

来源:百度知道 编辑:UC知道 时间:2024/05/27 20:02:42
如何在jsp页面 实现通过ArrayList结果集循环成两行两列
条件循环一个<table></table>,成两行两列,谢谢
我是在ACTION 里做了个Session 里面放的是数组

Good goods=new Goods();//实体bean

Good[] good=null; //数组
..
good=gb.SelectGoods(null,goods);//得到ArrayList放数组里 (gb.SelectGoods(null,goods);--方法)
..
session.setAttribute("i",good);
...
在页面获取Session
...jsp页面
<% Goods[] good=(Goods[])session.getAttribute("i");

for(int i= 0;i<good.length;i++){
%>
<table>
<tr>
<td><%=good[i].getid%></td>
</tr>
</table>
<%}%>

就是想页面再循环for(){<table>..</table>}成两行两列

取模2,根据模的结果来控制tr td的显示
我基本不写jsp代码,给你个asp例子,看懂了自己改
<table>
<%
i=0
while not rs.eof
if i mod 2=0 then response.write "<tr>"
Response.write "<td>"&rs(0)&"</td>"
if i mod 2=0 then response.write "</td>"
i=i+1
rs.movenext
next
%>
</table>

<div class="box_cont">
<table class="lb_table">
<c:forEach var="item" items="${list}" varStatus="index">
<c:if test="${index.count <= 2}">
<tr>
<td>${item.aa}</td>
<td>${item.bb}</td>
</tr>
</c:if>
</c:forEach>
</table>
</div>

如上,控制器传来list集合后,直接可用。

你的意思我不太明白,是不是ArrayList中有两条记录。然后要把它们显示出来吗?如果在struts下很好实现:例如students是类stude