https://www.myziyuan.com/
- ydcker
- jsp购物车实现!需要使用到session,Map等等!!\~~~~~
- 2021-02-15 15:30:01
- wolf8668
- 这是其中的一段代码,要项目的话加445899710HttpSession 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);}
- 2021-02-11 13:51:57
- hedianshui
- jsp购物车共享下谢谢, 最好有详细代码! 急,session 保存用户购物车信息 shoplist,购买一个商品 就往集合里面存入一个商品实体。
- 2021-02-11 13:51:57