日期:2014-05-16 浏览次数:20414 次
cart.jsp 代码<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%> <%@ page import="bean.*" %> <%@ page import="java.util.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>购物车</title> <script type="text/javascript"> <!-- function Ok(){ return true;//返回true模态窗口关闭;返回false模态窗口不关闭; } function update(id,i) { form1.action="/OnlineShop/servlet/ShoppingServlet?method=update &bookId="+id; form1.submit(); } </script> <% String error = (String)request.getAttribute("error"); String nulls = (String)request.getAttribute("null"); String ok = (String)request.getAttribute("ok"); if(error != null && error.equals("1")){ %> <script>alert('您的购物数量大于库存了!')</script><% } if(nulls != null && nulls.equals("1")){ %> <script>alert('您的购物车中没有商品!')</script><% } if(ok != null && ok.equals("1")){ %> <script>alert('恭喜您,购物成功!')</script><% } %> </head> <body style="margin:0px;padding:0px;"> <form name="form1" action="" method="post"> <table bgcolor="#006666" border="0" cellpadding="1" cellspacing="1" align="center" width="620"> <tr bgcolor="#996600"> <td align="center" valign="middle">商品名称</td> <td align="center" valign="middle">单价 (会员)</td> <td align="center" valign="middle">数量</td> <td align="center" valign="middle">总价</td> <td align="center" valign="middle">修改数量</td> <td align="center" valign="middle">删除</td> </tr> <% Cart cart = (Cart)session.getAttribute("cart"); if(cart == null ){ %> <tr bgcolor="#fff9ec"><td colspan="6" align="center" valign="middle"><font size="1" color="red">购物车中一件商品也没有!</font></td></tr> <%}else{ ArrayList<CartItem> al = cart.getCart(); Iterator<CartItem> it = al.iterator(); while(it.hasNext()){ CartItem cartItem = it.next(); %> <tr bgcolor="#fff9ec"> <td valign="middle" align="center"><%=cartItem.getName()%></td> <td valign="middle" align="center"><%=cartItem.getPrice()%>元</td> <td valign="middle" align="center"><input class="input1" type="text" value="<%=cartItem.getQuantity()%>" name="updateBookQuantity<%= cartItem.getId() %>"></input></td> <td valign="middle" align="center"><%=cartItem.totalPrice()%>元</td> <td align="center" valign="middle"> <input type="button" value="修改数量" onclick="update(<%= cartItem.getId()%>)" style="background-image:url(../images/btn_03.jpg)"/></td> <td align="center" valign="middle"> <a href="/OnlineShop/servlet/ShoppingServlet?method=delete& bookId=<%=cartItem.getId() %>"> <img src="../images/trash.gif" border="0" height="17" width="15" alt=""> </a> </td> </tr> <%}%> <tr bgcolor="#fff9ec"> <td colspan="6" align="center">购物车里有商品:<%=cart.getTotalQuantity()%> 件共计:<%=cart.getTotalMoney()%>元 </td> </tr> <%}%> <tr bgcolor="#ffffff"> <td colspan="6" align="center"> <a href="/OnlineShop/servlet/ShoppingServlet?method=removeAll"> <img alt="" src="../images/cart02.gif" border=0/> </a> <a href="/OnlineShop/servlet/ReckoningServlet"> <img alt="" src="../images/cart03.gif" border=0/> </a> </td> </tr> <tr><td colspan="6"vali