日期:2014-05-17 浏览次数:20757 次
public boolean removeItem(String id){
CartItem cartItem=null;
for(int i=0;i<cart.size();i++){
cartItem=cart.get(i);
if(cartItem.getId().equals(id)){
cart.remove(id);
return true;
}
}
return false;
}
out.println("<a href=\"/ShoppingCart/deleteServlet?id="+item.getId()+"\">刪除</a>");
HttpSession session=req.getSession();
ShoppingCart cart=(ShoppingCart)session.getAttribute("shoppingcart");
String id=req.getParameter("id");
if(cart!=null&&id!=null&&!"".equals(id)){
cart.removeItem(id);
out.println("刪除成功!");
}
else{
out.println("刪除失敗!");
}
for(int i=0;i<items.size();i++){
item=items.get(i);
out.println("<tr>");
out.println("<td>");
out.println(item.getName());
out.println("</td>");
out.println("<td>");
out.println(item.getPrice());
out.println("</td>");
out.println("<td>");
out.println(item.getQuantity());
out.println("</td>");
out.println("<td>");
out.println(item.getSum());
out.println("</td>");
out.println("<td>");
out.println("<a href=\"/ShoppingCart/deleteServlet?id="+item.getId()+"\">刪除</a>");
out.println("</td>");
out.println("</tr>");
}
HttpSession session=req.getSession(); ShoppingCart cart=(ShoppingCart)session.getAttribute("shoppingcart"); String id=req.getParameter("id"); if(cart!=null&&id!=null&&!"".equals(id)){ cart.removeItem(id); out.println("刪除成功!"); } else{