例如,我有以下数据:
这是我通过名称" country"。
从数据库收到的数据现在我想显示这些数据,使其在加载jsp时看起来像这样:
我在jsp中编写的代码如下:
<table>
<tr>
<td>
<c:forEach items="${country}" var="country">
${country.index} ${country.title}<br/>
</c:forEach>
</td>
</tr>
</table>
&#13;
在这里,我只能在一行中获得所有国家/地区的名称。如果我想将结果拆分为2栏,我该怎么办?我必须对代码做出哪些更改?
答案 0 :(得分:0)
添加另一列并循环行(如果你想这样做,也可以在两列上循环)
<table>
<c:forEach items="${country}" var="country">
<tr>
<td>
${country.index}
</td>
<td>
${country.title}
</td>
</tr>
</c:forEach>
</table>
答案 1 :(得分:-1)
如果country
中有N个元素,则halfIndex
为N/2
。
<table>
<tr>
<td>
<c:forEach items="${country}" var="countrySetA" begin="0" end="${halfIndex}">
${countrySetA.index} ${countrySetA.title}<br/>
</c:forEach>
</td>
<td>
<c:forEach items="${country}" var="countrySetB" begin="${halfIndex}">
${countrySetB.index} ${countrySetB.title}<br/>
</c:forEach>
</td>
</tr>
</table>