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.
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: