Java中的ShoppingCart

时间:2011-03-28 09:55:12

标签: java jsp

我有一个Product类和CartItem类来保存产品,还有一个shoppingCart类,其中包含从购物车添加/删除项目的方法。

我目前正在使用XML文件来存储产品。您将如何在JSP页面中显示产品列表。您如何遍历产品列表,列出每个产品名称,描述和尺寸及其价格?

1 个答案:

答案 0 :(得分:1)

  

如何在JSP页面中显示产品列表。如何遍历产品列表,列出每个产品名称,描述和尺寸及其价格

使用JSTL <c:forEach>迭代集合。使用EL ${}来访问和显示bean属性。使用HTML <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>