1. Jsp写的购物车代码 这是其中的一段代码,要项目的话加445899710
【怎么写购物车代码】HttpSession session = request.getSession(false);
if(session==null){
dispatcher = request.getRequestDispatcher("show.jsp");
dispatcher.forward(request, response);
}
FoodBean foodBean = (FoodBean)session.getAttribute("FoodToAdd");
Map cart = (Map)session.getAttribute("cart");
if(cart==null){
cart = new HashMap();
session.setAttribute("cart", cart);
}
CartItemBean cartItem = (CartItemBean)cart.get(foodBean.getFoodID());
if(cartItem==null){
cart.put(foodBean.getFoodID(), new CartItemBean(foodBean,1));
}else{
cartItem.setNumber(cartItem.getNumber()+1);
}
2. 用JAVA+SERVLET+JAVABEAN写购物车代码 你用
写一个购物车的bean,里边有产品和数量
public class CarProduct {
private XXX XXX;
private int count;
public Book getXXX() {
return XXX;
}
public void setXXX(XXX XXX) {
this.XXX= XXX;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
用session存购物车里的东西,提交订单的时候,把购物车清空就行,
3. jsp购物车代码 //shopping.html shopping stor <body>