【问题标题】:Shopping car JSP : Need item rows to stay on the product page when one or more items are selected and submitted to cart购物车 JSP :当一个或多个商品被选择并提交到购物车时,需要商品行留在产品页面上
【发布时间】:2013-02-28 20:58:03
【问题描述】:

我有一个购物车应用程序,其中的项目显示为表格的行。在每个结束时 行,有一个“添加到购物车”提交按钮。目前,当我单击该按钮时 整个页面消失,并在表单提交给 servlet 时出现错误 404 页面。我想要的是当一排 提交后,其余行保留,只有单击的行更改颜色。 随着用户添加更多行(项目),这些行中的每一行都应该改变颜色。 我得到了不断变化的颜色 部分,但还没有弄清楚如何让其余的行留在页面上。

       <h1> Here is the product list as per your category selection</h1>

<table cellpadding="10" border="1" id="tbl">
    <tr valign="bottom" style="background-color: #FF00FF">
        <th align="left">Sl No</th>
        <th align="left">Prod ID</th>
        <th align="left">Unit Price</th>
        <th align="left">Quantity</th>
        <th align="left"></th>
    </tr>
    <form name="tableForm" >  
        <c:forEach items="${listInServlet1}" var="regBean">
            <tr style="background-color: #00FFFF">
                <input type="hidden" value="sval" name="qtyTextHidden" />
                <input type="hidden" name="reagentId" value="<c:out Value = " ${regBean.prodId}
                "/>" />
                <td>
                    <c:out Value="${regBean.prodCount}" />
                </td>
                <td>
                    <c:out Value="${regBean.prodId}" />
                </td>
                <td>
                    <c:out Value="${regBean.price}" />
                </td>
                <td>
                    <input name="qtyText" type="text" size="2" value="" 
                onChange="calculateTotalPrice(this, '${regBean.price}')"
                    />
                </td>
                <td>
                    <input name="totalprice" type="text" size="2" value="0" />
                </td>
                <td>
                    <input type="submit" value="Add to Cart" name="addToCrtBtn" 
          onClick="submitValues(event, '${regBean.prodCount}', '${regBean.price}')"
                    />
                </td>
            </tr>
        </c:forEach>
    </form>
</table>
<table>
    <tr>
        <td>
            <form name="tableForm" method="post" action="/myapp/myservlet">
                <input type="submit" value="Done" id="submitOrder" />
            </form>
        </td>
    </tr>
</table>

【问题讨论】:

标签: java javascript jsp cart shopping


【解决方案1】:

向您提交购物车数据的 servlet 发出 ajax 请求。当响应从服务器返回时,更改行的颜色。为了确定您必须提交哪些行数据,请使用行的“id”属性。

【讨论】:

    【解决方案2】:

    拉古,

    您可以选择 imran 建议的答案。我认为这将是实现这一点的最佳方法,但是还有另一种复杂的方法,在您将 ATC[添加到购物车] 提交到 servlet 后,一旦您从 servlet 重定向添加到类别页面一次再次连同已添加的产品 ID 的参数列表。使用此列表,您可以轻松地为已有项目显示彩色行。

    【讨论】:

    • 你能提供一些示例 servlet 代码吗?我认为这是一个很好的策略。我试过了,但是 servlet 重定向和 AJAX 响应与页面不匹配,我在显示页面时遇到问题
    猜你喜欢
    • 2020-01-14
    • 1970-01-01
    • 2018-06-03
    • 1970-01-01
    • 1970-01-01
    • 2015-06-01
    • 2010-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多