我有以下购物车形式
这是此表单的源代码
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ROOM SERVICE ORDER SYSTEM</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../WEB-INF/css/jquery.mobile.structure- 1.0.1.css" />
<link rel="stylesheet" href="../WEB-INF/css/jquery.mobile-1.0.1.css" />
<link rel="stylesheet" href="../WEB-INF/css/style.css" />
<script src="../WEB-INF/js/jquery-1.7.1.min.js"></script>
<script src="../WEB-INF/js/jquery.mobile-1.0.1.min.js"></script>
</head>
<body>
<!--------------page displayed in the browser---------------->
<div data-role="page" id="home" data-theme="c">
<div data-role="content">
<form action="orderServlet" method="POST">
<div data-role="header">
<div id="title">
<h3>ROOM SERVICE </h3>
</div>
<div id="menu">
<div style="float: left;width:10px;height: 1px;">
<a href="../index.jsp"><img src="../js/images/arrow.png" alt=""/></a>
</div>
<h3>CART</h3>
</div>
</div>
<!-----class adds extra padding and margin inside the page content------>
<div data-role="main" class="ui-content">
<div id ="center_sub">
<table>
<!---------------------------------------------------->
<tr id ="trsub">
<td id="tdsub_item">Item</td>
<td id="tdsub_price">Price</td>
<td id="tdtitle_qty">Qty</td>
<td id="tdtitle_delete">Delete</td>
</tr>
<c:forEach var = "orderitem" items = "${order.orderdetails}">
<tr id="trsub">
<td id="tdsub_item">
<input type="hidden" name="item" value="${orderitem.item.itemid}" />
<c:out value="${orderitem.item.itemname}"/>
</td>
<td id="tdsub_price">
<c:out value="${orderitem.item.itemprice}"/>
</td>
<input type="hidden" name="item" value="${orderitem.item.tax}" />
<td id="tdsub_qty">
<select name ="select" >
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</td>
<!---------Check box Delete----------->
<td id="tdsub_delete">
<input type="checkbox" name="Delete" value="">
</td>
</tr>
</c:forEach>
<!---------------------------------------------------->
</table>
</div>
</div>
<!----- End of class adds extra padding and margin inside the page content------>
<!--------- button cear cart and update cart----------->
<div id="wrapp-button">
<!------------ button Clear Cart--------------->
<div class="button-clear">
<input type="button" name="Clear" value="Clear Cart">
</div>
<!-------------------------------------------->
<!-------------button Update Cart-------------->
<div class="button-update">
<input type="submit" name ="Update" value="Update Cart">
</div>
<!----------------------------------------------->
</div>
<!----------------------------------------------------------->
<div style="width:100%;padding-top: 15px;">
<table style="border: 1px solid #4596ce;">
<tr>
<td style="width:85%;">Subtotal</td>
<td style="width:15%;">12</td>
</tr>
<tr>
<td style="width:85%;">In room delivery charge (fixed)</td>
<td style="width:15%;">$1.10</td>
</tr>
<tr>
<td style="width:85%;color: #000000;">Total</td>
<td style="width:15%;"><c:out value=""/></td>
</tr>
<tr>
<td style="width:100%;">(Tax included in above TOTAL: 10%)</td>
<td style="width:100%;">$4.30</td>
</tr>
</table>
</div>
<!---------Button Proceed to Order--------->
<div id="footer_sub">
<input type="submit" name="Proceed" value="Proceed to Order">
</div>
<!------------------------------------------>
</form>
</div>
</div>
</body>
</html>
当我们点击更新购物车时如何具体到达行中的项目,因此它只会根据我们从网络发送的参数更新项目,这些参数应该由id特定但我不知道如何做到这一点。任何人都可以指出如何做到这一点? 感谢。
答案 0 :(得分:0)
对于这个approch,您可以将itemid
作为值传递给复选框,这样当您提交表单时,只会设置您选择的那些值,然后您可以使用{{1将这些值转换为字符串数组然后检查订单列表中是否存在此项目(如果存在),然后从列表中删除该项目:
request.getParameterValues()
在servlet中
<!---------Check box Delete----------->
<td id="tdsub_delete">
<input type="checkbox" name="Delete" value="${orderitem.item.itemid}">
</td>