ShoppingCart in Java

拥有回忆 提交于 2019-12-08 14:35:47

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/5457310/shoppingcart-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!