我有一個購物車應用程序,其中的項目以行的形式顯示。在每個 行末尾都有一個「添加到購物車」提交按鈕。目前,當我點擊該按鈕 時,整個頁面消失,並且在表單提交給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>
調查ajax調用。 – 2013-03-13 03:44:33
你可以使用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