2013-03-13 41 views
0

我有一個購物車應用程序,其中的項目以行的形式顯示。在每個 行末尾都有一個「添加到購物車」提交按鈕。目前,當我點擊該按鈕 時,整個頁面消失,並且在表單提交給servlet時出現錯誤404頁面。我想要的是,當提交一行 時,剩下的行將保留,只有被點擊的行纔會改變顏色。 隨着用戶添加更多行(項目),這些行中的每一行都應該改變顏色。 我有變化的顏色 部分,但一直未能弄清楚如何使其餘的行留在頁面上。購物車JSP:選擇一個或多個項目並將其提交到購物車時,需要項目行留在產品頁面上

 <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> 
+0

調查ajax調用。 – 2013-03-13 03:44:33

+0

你可以使用jquery來調用servlet。 [這裏] [1]就是一個例子。 [1]:http://stackoverflow.com/questions/3614703/calling-a-servlet-from-a-jsp-page-using-jquery-ajax – 2013-03-13 04:00:35

回答

0

向您提交購物車數據的servlet發出ajax請求。並且當從servelt返回的響應改變了該行的顏色時。用於標識您必須提交的行數據使用行的「id」屬性。

0

Raghu,

你可以去imran提出的答案。我認爲這將是實現這一目標的最佳方式,但是再次有另一種方式是複雜的,在您將ATC [添加到購物車]提交給servlet時,一旦您從servlet重定向添加到類別頁面一次再次連同已添加的產品ID參數列表。通過此列表,您可以輕鬆地顯示已經項目的彩色行。

+0

你能提供一些示例servlet代碼?我認爲這是一個很好的策略。我嘗試過,但servlet重定向和AJAX響應不匹配到頁面,並且顯示頁面時出現問題 – Raghu 2013-03-13 21:05:19

相關問題