我有一张表,表示客户购物车中有“从购物车中移除”按钮的所有商品。它使用户能够删除购物车中的某个产品。这是代码:
<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;">₱ ${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。我不知道为什么会这样。
答案 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;">₱ ${product.totalPrice()}</td>
<td><input type="submit" class="btn btn-warning btn-xs"
value="Remove from cart"></td>
</tr>
</form>
</c:forEach>
</tbody>
</table>