Use the HTML <table> element to represent the table in HTML. Use JSTL <c:forEach> to iterate over the list in JSP.
eg.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> ... <table> <c:forEach items="${list}" var="item"> <tr> <td><c:out value="${item}" /></td> </tr> </c:forEach> </table>
You only have a design flaw in your code. You split the related data over two independent lists. This will make the final approach as ugly as
<table> <c:forEach items="${TAREWEIGHT}" var="tareWeight" varStatus="loop"> <c:set var="barCode" value="${BARCODE[loop.index]}" /> <tr> <td><c:out value="${tareWeight}" /></td> <td><c:out value="${barCode}" /></td> </tr> </c:forEach> </table>
I suggest creating your own class for storing related data. For instance.
public class Product { private BigDecimal tareWeight; private String barCode;
so that you get a List<Product> , which can be represented as follows:
<table> <c:forEach items="${products}" var="product"> <tr> <td><c:out value="${product.tareWeight}" /></td> <td><c:out value="${product.barCode}" /></td> </tr> </c:forEach> </table>
after placing it in the request area as follows:
request.setAttribute("products", products);
See also:
source share