向购物车添加商品出错
这是servlet中的代码:public void shopcar(HttpServletRequest request, HttpServletResponse response)
throws Exception {
response.setContentType("text/html;charset=GBK");
PrintWriter out = response.getWriter();
String strId=request.getParameter("productID");
int id;
if(strId==null){
id=1;
}else{
id=Integer.parseInt(strId);
}
productservice service=new productservice();
product products=new product();
products=service.showproduct(id);
//String book_number=request.getParameter("book_num");
//int number;
//if(book_number==null){
//number=1;
//}else{
//number=Integer.parseInt(book_number);
//}
//products.setBook_number(number);
HttpSession s=request.getSession();
List<product> list;
if(s.getAttribute("shop")==null){
list=new ArrayList<product>();
list.add(products);
s.setAttribute("shop", list);
}else {
list=(List)s.getAttribute("shop");
list.add(products);
}
/*RequestDispatcher
dispatcher=request.getRequestDispatcher("../ShopCart/shopcart.jsp");
dispatcher.forward(request, response);*/
HttpSession session =request.getSession();
session.setAttribute("shop", list);
response.sendRedirect("../cart/cart.jsp");
out.flush();
out.close();
}
这是点击商品上的购买时的代买:
<a href="<%=request.getContextPath()%>/servlet/productServlet?operate=shopCar&productID=<%=products.getProducdID()%>">购买</a>
这是cart.jsp中的代码:
<%
//int pId=Integer.parseInt(request.getParameter("productID"));
List<product> proList=(ArrayList)request.getAttribute("proList");
product pro=new product();
//productservice ps=new productservice();
//pro=ps.showproduct(pId);
%>
<%
List<product> shopCar=(ArrayList)session.getAttribute("shopCar");
product pros=new product();
%>
<link rel="stylesheet" href="glCSS/cart.css" type="text/css"></link>
</head>
<body>
<center>
<div id="tou" >
<div id="n1" >
<div id="n2" >
<div id="z1" >我的购物车</div>
............
<%
double sum=0.0;
for(int i=0;i<shopCar.size();i++){
pros=(product)shopCar.get(i);
sum=sum+pros.getProductPrice();
%>
<table border="0" width="1000" height="50" bordercolor="#336699">
<tr>
<td width="160"><%=i+1 %></td>
<td width="160"><%=pros.getProducdID() %></td>
<td width="160"><%=pros.getProductName() %></td>
<td width="160"><%=pros.getProductClass() %></td>
<td width="160"><%=pros.getProductClass() %></td>
</tr>
</table>
<%} %>
<br>
<tr>
<td width="150"></td><td width="150"></td><td width="90">合计总金额:</td><%=sum %><td>¥</td><td width="150"></td>
</tr>
点击购买后购物车页面显示不出来 要么就是报错 我不知道那错了 帮我改下 谢谢了