JSP遍历对象列表 [英] Jsp iterate through object list

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

问题描述

我在遍历jsp槽列表时遇到麻烦.这是我称为表的对象类:

I'm having troubles iterating with jsp trough list/lists. Here is my object class called Table:

public class Table{

private String name;
private List<String> columns;
private List<Row> rows;

... continuing with getters and setters nothing more here

}

在我的Row类中,我只有Strings(例如:String name),没有任何列表.

In my Row class I have just Strings(ex: String name), no lists no nothing.

目前我有一些List<Table>,并且正在像这样迭代它:

Currently I have some List<Table> and I'm iterating trough it like this:

<c:forEach var='table' items='${requestScope.tables}'>
        <c:out value="{table.name}"></c:out>
</c:forEach>

仅用于测试..,它只打印{table.name} x次(表列表中表对象的正确数量).

Just for testing .. and it prints just {table.name} x times(the correct number of table objects in the table list).

我的最终目标是这样的(伪代码):

My final goal is something like this (pseudo code):

for each table in table list
     print name
     for each column in colum list
         print column
     end column list for
     for each Row in row list
         print Row.name
     end row list for
end table list for

有人可以帮我解决语法问题吗?

Could someone help me out with syntax?

推荐答案

<c:forEach var="table" items='${requestScope.tables}'>
        <c:out value="${table.name}"></c:out>

        <c:forEach var="column" items='${table.columns}'>
           <c:out value="${column}"></c:out>
        </c:forEach>

        <c:forEach var="row" items='${table.rows}'>
           <c:out value="${row.name}"></c:out>
        </c:forEach>

</c:forEach>

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

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