视图列表或单个对象的公共页面
我想编写通用页面来查看数据列表或单个对象。
在控制器中:
ArrayList<Table> tables;
request.setAttribute("tables", tables);
和 JSP:
<table >
<c:forEach var="table" items="${tables}">
<tr>
<th><c:out value=" ${table.name}" /></th>
</tr>
</c:forEach>
</table>
显示良好。
当我传递单个对象时 -
Table table;
request.setAttribute("table", table);
不显示任何内容;
比我尝试通过
Table tables;
request.setAttribute("tables", tables);
我有错误
Don't know how to iterate over supplied "items" in <forEach>
这是一个非常简单的例子,我的应用程序必须查看该对象的大量数据,并使用相同的代码创建两个相似的页面,这很愚蠢。 如何解决这个问题呢?将这个单个对象添加到列表中还是还有其他解决方案?
i want to write common page for viewing data list or single object.
In controller:
ArrayList<Table> tables;
request.setAttribute("tables", tables);
and JSP:
<table >
<c:forEach var="table" items="${tables}">
<tr>
<th><c:out value=" ${table.name}" /></th>
</tr>
</c:forEach>
</table>
Shows good.
When i pass single object -
Table table;
request.setAttribute("table", table);
does not show anything;
Than i try pass
Table tables;
request.setAttribute("tables", tables);
i have error
Don't know how to iterate over supplied "items" in <forEach>
This is a pretty simple example, my application must view a lot of data of this object, and make two similar pages with the same code it silly.
How to solve this problem? add this single object to the list or there is another solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您想传递单个元素而不是列表。解决此问题的一种方法是构建一个包含单个元素的列表并传递它。使用以下命令创建仅包含一个元素的列表。
It seems like you want to pass single element instead of list. One way to solve this is to build a list with single element and pass it. Use following to create list with only one element in it.
这是因为 jstl
forEach
标记需要一个列表,而您正在传递一个对象。尝试传递一个单元素列表:
It's because jstl
forEach
tag is expecting a List, and you are passing a single object.Try passing a one element list: