为了美观,页面控制中经常会限制每行显示的数据个数,当数据是在程序中动态生成的时候,如通过数据库查询得到时,可以在Action中将数据放入list,通过request.setAttribute("catalogType",list);的方式传递到页面,然后在页面用用logic:iterator标签按如下方式迭代显示,即可达到每行显示两个元素的效果。
<table width="120" height="354" border="0" cellpadding="0" cellspacing="0" bgcolor="#F0FAEB">
<tr>
<td height="5" colspan="2"></td>
</tr>
<tr>
<logic:iterate id="element" name="catalogType" scope="request" indexId="typeIndex">
<%
if (typeIndex.intValue()%2==0 && typeIndex.intValue() != 0)
{
%>
</tr><tr>
<%
}
%>
<td width="62">
<bean:write name="element" property="YourPropertyName"/>
</td>
</logic:iterate>
</tr>
</table>
<tr>
<td height="5" colspan="2"></td>
</tr>
<tr>
<logic:iterate id="element" name="catalogType" scope="request" indexId="typeIndex">
<%
if (typeIndex.intValue()%2==0 && typeIndex.intValue() != 0)
{
%>
</tr><tr>
<%
}
%>
<td width="62">
<bean:write name="element" property="YourPropertyName"/>
</td>
</logic:iterate>
</tr>
</table>