如何以表格格式显示ArrayList?
我的 Servlet 代码中有一个 ArrayList。现在,我想以表格格式显示 ArrayList。我怎样才能实现这个目标?
例如
ArrayList dataList = new ArrayList();
// dataList Add Item
out.println("<h1>" + dataList +"</h1>"); // I want to view it in tabular format.
I have an ArrayList
in my Servlet code. Now, I want to show that ArrayList
in a tabular format. How can I achive this?
E.g.
ArrayList dataList = new ArrayList();
// dataList Add Item
out.println("<h1>" + dataList +"</h1>"); // I want to view it in tabular format.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
表格采用 HTML 格式,由
元素表示。您应该使用 JSP 作为 HTML 代码来将视图与控制器分开(这将大大提高可维护性)。您可以使用 JSTL 来控制 JSP 中的流程。您可以使用 JSTL
标签来迭代集合。在 servlet 中,将列表放入请求范围并转发到 JSP:
在
/WEB-INF/dataList.jsp
中,您可以将其呈现在 HTML< /code> 如下:
另请参阅:
Tables are in HTML to be represented by
<table>
element. You should be using JSP for HTML code to separate view from the controller (which will greatly increase maintainability). You could use JSTL to control the flow in JSP. You can use JSTL<c:forEach>
tag to iterate over a collection.In the servlet, put the list in the request scope and forward to a JSP:
In the
/WEB-INF/dataList.jsp
, you can present it in a HTML<table>
as follows:See also:
请参阅下面
ArrayList
的工作原理祝你好运!!!
See below how
ArrayList
worksGood Luck!!!
您必须使用 HTML Tables 而不是 H1 元素,迭代对象列表并打印它们的属性
You would have to go with HTML Tables instead of H1 elements, iterate through the list of objects and print their properties