[英]Jsp iterate through object list
I'm having troubles iterating with jsp trough list/lists. 我在用jsp槽列表进行迭代时遇到麻烦。 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
}
In my Row class I have just Strings(ex: String name), no lists no nothing. 在我的Row类中,我只有Strings(例如:String name),没有列出就什么也没有。
Currently I have some List<Table>
and I'm iterating trough it like this: 目前,我有一些
List<Table>
并且正在像这样迭代它:
<c:forEach var='table' items='${requestScope.tables}'>
<c:out value="{table.name}"></c:out>
</c:forEach>
Just for testing .. and it prints just {table.name}
x times(the correct number of table objects in the table list). 仅用于测试..,它仅打印
{table.name}
x次(表列表中表对象的正确数量)。
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>
You forgot the dollar sign - ${table.name}
您忘记了美元符号-
${table.name}
Also, you should use double-quotes: var="table"
另外,您应该使用双引号:
var="table"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.