0
我有一个表格,代表客户的购物车中有“从购物车中删除”按钮的所有产品。它使用户能够移除购物车中的某个产品。以下是代码:为什么我的桌子这样表现?
<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都会被发送。我不知道为什么会发生这种情况。
哪里是“删除购物车”按钮的代码?如果按钮提交表单,它将包含您的$ {productsInCart}' – bhantol
中的所有'input:upc'字段在最后,我的朋友。 – saluyotamazing
明白了。它将提交所有UPC的表单,因此代码的行为应该与它应该一样。看起来像你想尝试删除只调用删除的产品。 – bhantol