在JSP中以2列

时间:2017-09-21 21:09:28

标签: jquery jsp jstl

例如,我有以下数据:

  1. 非洲
  2. 印度
  3. 澳大利亚
  4. USA
  5. 俄罗斯
  6. 这是我通过名称" country"。

    从数据库收到的数据

    现在我想显示这些数据,使其在加载jsp时看起来像这样:

    enter image description here

    我在jsp中编写的代码如下:

    
    
    <table>
        <tr>
            <td>
                <c:forEach items="${country}" var="country">
                    ${country.index} ${country.title}<br/>
                </c:forEach>
            </td>
        </tr>
    </table>
    &#13;
    &#13;
    &#13;

    在这里,我只能在一行中获得所有国家/地区的名称。如果我想将结果拆分为2栏,我该怎么办?我必须对代码做出哪些更改?

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个元素,则halfIndexN/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>