MVC构架的web数据库应用购物车代码

来源:百度知道 编辑:UC知道 时间:2024/06/23 22:18:35
现在做一个简单的网上书店。请教高手一个问题。
我将书籍查询结果放在session里面,然后在jsp页面上显示出来。
有多条信息,现在我想将其中一条或几条加入购物车该怎么做 哦????
急!!!!

先建个购物车的实体类
如:public class CartItemBean {
private FoodBean food; //餐品
private int quantity; //餐品数量

public CartItemBean(FoodBean foodToAdd, int number){
food = foodToAdd;
quantity = number;
}

public FoodBean getFood() {
return food;
}

public void setFood(FoodBean food) {
this.food = food;
}

public int getQuantity() {
return quantity;
}

public void setQuantity(int quantity) {
this.quantity = quantity;
}
}

建个Serblet
public class AddFoodToCart extends HttpServlet {

/**
* 购物车操作 Servlet 实现思路
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html; charset=GBK");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession(false);