ArrayList的表在JSP [英] ArrayList to Table in JSP

查看:84
本文介绍了ArrayList的表在JSP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ArrayList,我试图在表中显示它

I have an ArrayList and i am trying to display it in a table

......

ArrayList的行数= ....

ArrayList rows = ....

......

    <table cellspacing="1" cellpadding="4" border="3">
        <tr>
            <TH>
                Heading1
            </TH>
            <TH>
                Heading2
            </TH>
            <TH>
                Heading3
            </TH>
            <TH>
                Heading4
            </TH>
            <TH>
                Heading5
            </TH>
            <TH>
                Heading6
            </TH>
            <TH>
                Heading7
            </TH>
        </tr>

        <tr>
            <% for (int i = 0; i < rows.size(); i++) {
                for (int j = 0; j < 7; j++) {
            %>
            <td>
                <center>
                    <% out.println( ?????  ); %>
                </center>
            </td>
            <% } %>
        </tr>
        <% } %>
    </table>

但我有显示正确的数据的麻烦。

but i am having trouble displaying the correct data.

推荐答案

好了一件事,我怀疑你的外环应该启动&LT以上; TR&GT; 标签

Well for one thing, I suspect that your outer loop should start above the <tr> tag.

除此之外,一个ArrayList是一维结构(这并不奇怪,因为它是一个列表)。尝试在一个表中暗示它的二维显示此数据,但没有泛型你给了没有信息,以什么是包含在列表中。

Other than that, an ArrayList is a one-dimensional structure (not surprisingly, since it's a list). Trying to display this data in a table implies it's two dimensional, but without generics you've given no information as to what's contained within the list.

我处理这个事情是这样的:

I'd approach this something like this:

    /* header rows */

        <% for (int i = 0; i < rows.size(); i++) { 
           Object rowObj = rows.get(i);
        %>
        <tr>

            <% for (int j = 0; j < 7; j++) {
               // This RHS made up due to not knowing the class of objects
               // in your map, use something equivalent
               Object cell = rowObj.getEntry(j); 
            %>
            <td>
                <center>
                   <%=cell.toString()%>
                </center>
            </td>
            <% } %>
        </tr>
        <% } %>

这篇关于ArrayList的表在JSP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆