📄 showcart.jsp
字号:
<%@ page contentType="text/html; charset=GB2312" %>
<%@ include file="/gouwuche/common.jsp" %>
<%@page import="java.util.Collection,java.util.Iterator" %>
<jsp:useBean id="cart" scope="session"
class="shop.CartBean"></jsp:useBean>
<html>
<head><title>欢迎光临网上书店</title></head>
<body>
<%
request.setCharacterEncoding("GB2312");
String action=request.getParameter("action");
if(action!=null && action.equals("保存修改"))
{
String strItemNum=request.getParameter("itemnum");
int itemNum=Integer.parseInt(strItemNum);
// System.out.println(itemNum); //购物车中项目数
for(int i=0;i<itemNum;i++)
{
String strBookId=request.getParameter("book_"+i);
String strNum=request.getParameter("num_"+i);
//System.out.println(strBookId); //图书ID
//System.out.println(strNum); //图书数量
int productId=Integer.parseInt(strBookId);
int quantity=Integer.parseInt(strNum);
boolean bEnough=pDAO.isAmountEnough(productId,quantity);
if(bEnough == true)
{
// System.out.println("ok");
cart.setItemNum(new Integer(productId),quantity);
}
else
{
//System.out.println("false");
productBean pBean=pDAO.getproduct(productId);
out.println("<font color=\"red\" size=\"4\">");
out.print("《"+pBean.getProductName()+"》");
out.print("的库存数量只有"+pBean.getAmout()+"本,请调整购买数量!<p>");
out.println("</font>");
}
}
}
%>
<%
Collection cl=cart.getItems();
if(cl.size()<=0)
{
out.println("购物车中没有图书<p>");
%>
<a href="admingouwuche.jsp">继续购物</a>
<%
}
Iterator it=cl.iterator();
%>
<form name="theform" action="showcart.jsp" method="POST">
<table border="1" align="center">
<tr>
<th>书名</th>
<th>价格</th>
<th>数量</th>
<th>小计</th>
<th>取消</th>
</tr>
<%
int i=0;
while(it.hasNext())
{
CartItemBean cartItem=(CartItemBean)it.next();
productBean pBean=cartItem.getproduct();
int productId=pBean.getProductID();
String fieldNum="num_"+i;
String fieldBook="book_"+i;
%>
<tr>
<td><%=pBean.getProductName() %></td>
<td><%=pBean.getPrice() %></td>
<td>
<input type="text" name="<%=fieldNum%>"
value="<%=cartItem.getQuantity() %>"
size="2"/>
<input type="hidden" name="<%=fieldBook%>"
value="<%=productId%>"/>
</td>
<td><%=cartItem.getItemPrice() %></td>
<td><a href="delitem.jsp?id=<%=productId%>">删除</a></td>
</tr>
<%
i++;
}
%>
<tr>
<td>合计</td>
<td colspan="4"><%=cart.getTotalPrice() %></td>
</tr>
</table><p>
<input type="hidden" name="itemnum" value="<%=i%>"/>
<body><div align="left"> <input type="submit" name="action" value="保存修改"/></div></body>
<body><div align="center"><a href="admingouwuche.jsp">继续购物</a> <A href = "check-out.jsp">进入结算中心</A></div></body>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -