【问题标题】:How to return a single data from a row from a table in html?如何从html中的表中的一行返回单个数据?
【发布时间】:2016-10-13 05:17:14
【问题描述】:

我有一张表格,将产品存储在用户的购物车中。每行都有一个按钮,使用户能够从用户的购物车中删除单个产品。这是我的html的代码sn-p。

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

这是输出。

Product in cart table

我想要获取的值是存储在隐藏输入类型字段中的产品的 UPC。但是,当单击“从购物车中删除”按钮时,它会返回购物车中产品的所有 UPC。这是控制器的代码sn-p。

@RequestMapping(value="/customer/removeProduct", method=RequestMethod.POST)
public String removeProduct(@RequestParam(value = "upc") String upc, HttpServletRequest request){

    System.out.println(upc);
//      customerService.removeProductInCart(customer.getCustomer(request).getCartId(), upc);

    return "customer_home";
}

【问题讨论】:

    标签: java html jsp spring-mvc jstl


    【解决方案1】:

    您可能希望在每次迭代时创建表单以获取每一行的特定 upc,而不是包装整个表格。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-24
      • 2017-03-26
      • 2018-09-05
      • 1970-01-01
      • 2016-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多