日期:2014-05-17 浏览次数:20775 次
String id = request.getParameter("gid");
String quantity = request.getParameter("quantity");
String ctrl = request.getParameter("crtl");
ArrayList cart = new ArrayList();
ArrayList mycart = (ArrayList) session.getAttribute("mycart");
Iterator i = mycart.iterator();
if(ctrl.equals("change")){
while (i.hasNext()) {
CartBean temp = (CartBean) i.next();
if (temp.getGid().equals(id)) {
temp.setGquantity(quantity);
}
cart.add(temp);
}
} else if(ctrl.equals("delete")){
while (i.hasNext()) {
CartBean temp = (CartBean) i.next();
cart.add(temp);
if (temp.getGid().equals(id)) {
cart.remove(temp);
}
}
}
session.setAttribute("mycart", cart);
RequestDispatcher rd = request.getRequestDispatcher("cart.jsp");
rd.forward(request, response);