为什么我的桌子表现如此?

时间:2016-10-20 15:37:44

标签: html jstl

我有一张表,表示客户购物车中有“从购物车中移除”按钮的所有商品。它使用户能够删除购物车中的某个产品。这是代码:

<form
        action="${pageContext.request.contextPath}/customer/removeProduct"
        method="post">
        <input type="hidden" name="page" value="${page}">
        <table class="table">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Quantity</th>
                    <th>Amount</th>
                </tr>
            </thead>
            <tbody>
                <c:forEach items="${productsInCart}" var="product"
                    varStatus="status">
                    <input type="hidden" class="form-control" name="upc"
                            value="${product.getProduct().getUpc()}">
                    <tr class="warning">

                        <td>${product.getProduct().getName()}</td>
                        <td>${product.getQuantity()}</td>
                        <td style="color: green;">&#8369; ${product.totalPrice()}</td>
                        <td><input type="submit" class="btn btn-warning btn-xs"
                            value="Remove from cart"></td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>
    </form>

通过在控制器中发送其UPC(通用产品代码)来移除产品。但是,当单击“从购物车中移除”按钮时,将发送购物车中所有产品的UPC。我不知道为什么会这样。

1 个答案:

答案 0 :(得分:0)

基于我评论中的假设,你可以这样做:

<table class="table">
    <thead>
        <tr>
            <th>Name</th>
            <th>Quantity</th>
            <th>Amount</th>
        </tr>
    </thead>
    <tbody>
        <c:forEach items="${productsInCart}" var="product"
            varStatus="status">
            <form action="${pageContext.request.contextPath}/customer/removeProduct" method="post">
                <input type="hidden" name="page" value="${page}">
                <input type="hidden" class="form-control" name="upc"
                        value="${product.getProduct().getUpc()}">
                <tr class="warning">

                    <td>${product.getProduct().getName()}</td>
                    <td>${product.getQuantity()}</td>
                    <td style="color: green;">&#8369; ${product.totalPrice()}</td>
                    <td><input type="submit" class="btn btn-warning btn-xs"
                        value="Remove from cart"></td>
                </tr>
            </form>
        </c:forEach>
    </tbody>
</table>