1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
- <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>My JSP 'listcart.jsp' starting page</title>
- <script type="text/javascript">
- //删除商品
- function clearcartitem(bookid) {
- var result = window.confirm("您确定要删除该商品么?");
- if(result) {
- window.location.href = "${pageContext.request.contextPath }/CartDeleteServlet?bookid="+bookid;
- }
- }
- //清空购物车
- function clearcart() {
- var result = window.confirm("您确定要清空购物车么?");
- if(result) {
- window.location.href = "${pageContext.request.contextPath }/ClearCartServlet?action=2";
- }
- }
- //改变购物项数量
- function updateCart(input,id,oldvalue) {
- var quantity = input.value;
- //验证非零的正整数:^\+?[1-9][0-9]*$
- var reg= /^\+?[1-9][0-9]*$/;
- var result = window.confirm("请确认改为:" + quantity);
- //判断输入是否为正整数
- if(!reg.test(quantity)) {
- alert("参数不合法!");
- input.value = oldvalue;
- return;
- }
-
- if(result) {
- window.location.href="${pageContext.request.contextPath}/UpdateCartServlet?bookid="+id + "&quantity=" + quantity;
- } else {
- input.value = oldvalue;
- }
- }
- </script>
- </head>
- <body>
- <c:if test="${!empty(cart.map) }">
- <table border="1px" cellspacing="0" align="center">
- <tr>
- <td>图书名称</td>
- <td>图书作者</td>
- <td>单价</td>
- <td>数量</td>
- <td>小计</td>
- <td>操作</td>
- </tr>
- <c:forEach var="me" items="${cart.map }">
- <tr>
- <td>${me.value.book.name }</td>
- <td>${me.value.book.author }</td>
- <td>${me.value.book.price }</td>
- <td><input type="text" name="quantity"
- value="${me.value.quantity }" style="width: 30px"
- onchange="updateCart(this,${me.value.book.id },${me.value.quantity })">
- </td>
- <td>${me.value.price }</td>
- <td><a href="javascript:clearcartitem(${me.value.book.id })">删除</a>
- </td>
- </tr>
- </c:forEach>
- <tr>
- <td colspan="4" style="display: block; text-align: center">合计</td>
- <td>${cart.price }</td>
- <td><a href="buySuccess.jsp">购买</a></td>
- </tr>
- <tr>
- <td colspan="2"><a href="javascript:clearcart()">清空购物车</a></td>
- <td colspan="4"><a href="/shopping/ListBookServlet"
- >返回主页面</a></td>
- </tr>
- </table>
- </c:if>
- <c:if test="${empty(cart.map) }">
- <p>购物车为空</p>
- <p>
- <a href="/shopping/ListBookServlet">返回主页面</a>
- </p>
- </c:if>
- </body>
- </html>
|