我有一个购物车应用程序,其中的项目以行的形式显示。在每个 行末尾都有一个“添加到购物车”提交按钮。目前,当我点击该按钮 时,整个页面消失,并且在表单提交给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