user478636
user478636

Reputation: 3424

ShoppingCart in Java

i have a Product class and CartItem class that holds the product, and a shoppingCart class that contains the methods for adding/removing items from the cart.

I am currently using an XML file to store the products. How would you display a list of products in a JSP page. How do you iterate through the list of products, listing each products name, description, and size and its price?

Upvotes: 0

Views: 566

Answers (1)

BalusC
BalusC

Reputation: 1109132

how would you display a list of products in a JSP page. How do you iterate through the list of products, listing each products name, description, and size and its price

Use JSTL <c:forEach> to iterate over a collection. Use EL ${} to access and display bean properties. Use HTML <table> to markup it as a table.

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<table>
    <c:forEach items="${products}" var="product">
        <tr>
            <td>${product.name}</td>
            <td>${product.description}</td>
            <td>${product.size}</td>
            <td>${product.price}</td>
        </tr>
    </c:forEach>
</table>

Upvotes: 1

Related Questions