开发者

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 currentl开发者_运维问答y 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?


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜