java购物车用servlet做,sql数据库,能实现基本增加、删除、修改商品,结账,然后下订单,求源代码 5
展开全部
加入购物车的代码:
//把商品保存到session中
HttpSession session=request.getSession();
List<Goods> list=(List) session.getAttribute("list");
int gid=Integer.parseInt(request.getParameter("gid"));
int num=Integer.parseInt(request.getParameter("num"));
Goods goods=null;
if(list==null || list.size()<0){
list=new ArrayList();
}else{
for (Goods g : list) {
if(g.getGid()==gid){
goods=g;
g.setSum(g.getSum()+num);
break;
}
}
}
if(goods==null){
goods=goodsDao.queryGoodsByG_id(gid);
goods.setSum(num);
list.add(goods);
}
session.setAttribute("list", list);
request.getRequestDispatcher("/index.jsp").forward(request, response);
增加、删除、修改商品差不多,只是sql语句不同
//把商品保存到session中
HttpSession session=request.getSession();
List<Goods> list=(List) session.getAttribute("list");
int gid=Integer.parseInt(request.getParameter("gid"));
int num=Integer.parseInt(request.getParameter("num"));
Goods goods=null;
if(list==null || list.size()<0){
list=new ArrayList();
}else{
for (Goods g : list) {
if(g.getGid()==gid){
goods=g;
g.setSum(g.getSum()+num);
break;
}
}
}
if(goods==null){
goods=goodsDao.queryGoodsByG_id(gid);
goods.setSum(num);
list.add(goods);
}
session.setAttribute("list", list);
request.getRequestDispatcher("/index.jsp").forward(request, response);
增加、删除、修改商品差不多,只是sql语句不同
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询