"public void indexFloor(HttpServletRequest req, HttpServletResponse resp)\n\t\t\tthrows ServletException, IOException {\n\n\t\tPcodeService service =new PcodeService();\n\t\tList floorInfo=service.getFloorInfo("4");\n\t\tString jsonString = JSON.toJSONString(floorInfo);\n\t\tresp.getWriter().write(jsonString);\n\t}\n\tpublic void hotProduct(HttpServletRequest req, HttpServletResponse resp)\n\t\t\tthrows ServletException, IOException {\n\n\t\tList hotProducts=service.findFloorsHotProducts(0,12);\n\t\tString jsonString =JSON.toJSONString(hotProducts);\n\t\tresp.getWriter().write(jsonString);\n\t}\n\tpublic void navigationBar(HttpServletRequest req, HttpServletResponse resp)\n\t\t\tthrows ServletException, IOException {\n\n\t\tProductService service =new ProductService();\n\t\tList categories = service.navigationBar();\n\t\tString jsonString = JSON.toJSONString(categories);\n\t\tresp.getWriter().write(jsonString);\n\t}\n\tpublic void productListByCid(HttpServletRequest req, HttpServletResponse resp)\n\t\t\tthrows ServletException, IOException {\n\t\tString cid=req.getParameter("cid");\n\t\tString currentPageStr =req.getParameter("currentPage");\n\t\tint currentPage=1;\n\t\tif(currentPageStr!=null && !"".equals(currentPageStr)){\n\t\t\tcurrentPage =Integer.valueOf(currentPageStr);\n\t\t}\n\t\tProductService service=new ProductService();\n\t\tPageBean pageBean=service.findProductListByCid(cid,currentPage,pageSize);\n\t\treq.setAttribute("pageBean",pageBean);\n\t\tSystem.out.println("ProductListByCidServlet.doGet-pageBean: " +pageBean);\n\t\tList hisProductList=new ArrayList();\n\t\tCookie[] cookies=req.getCookies();\n\t\tif(cookies!=null){\n\t\t\tfor(Cookie cookie:cookies){\n\t\t\t\tString name =cookie.getName();\n\t\t\t\tif("pids".equals(name)){\n\t\t\t\t\tString pids=cookie.getValue();\n\t\t\t\t\tString[] pidArr=pids.split("&");\n\t\t\t\t\tfor(String pid:pidArr){\n\t\t\t\t\t\tProduct product=service.productInfo(pid);\n\t\t\t\t\t\thisProductList.add(product);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\treq.setAttribute("hisProductList",hisProductList);\n\t\treq.getRequestDispatcher("product_list.jsp").forward(req,resp);\n\t}\n\tpublic void productInfo(HttpServletRequest req, HttpServletResponse resp)\n\t\t\tthrows ServletException, IOException {\n\t\tString pid=req.getParameter("pid");\n\t\tProductService service=new ProductService();\n\t\tProduct product=service.productInfo(pid);\n\t\treq.setAttribute("product",product);\n\t\tString pids =pid;\n\t\tCookie[] cookies=req.getCookies();\n\n\t\tif(cookies!=null){\n\t\t\tfor(Cookie cookie : cookies) {\n\t\t\t\tString name=cookie.getName();\n\t\t\t\tif("pids".equals(name)){\n\t\t\t\t\tpids =cookie.getValue();\n\t\t\t\t\t//有名为pids这个cookie,则获取其存储的值,\n\t\t\t\t\t/*每次在原值的前面拼接这一次访问的pid\n\t\t\t\t\t原则是:1)将最新访问的放在最前面.\n\t\t\t\t\t\t例如:如果获取的cookie值为 1,2,3 则商品访问顺序为先访问的3-->2-->1,\n\t\t\t\t\t\t即最新一次访问商品ID是1\n\t\t\t\t\t\t2)如果有重复商品,则先将字符串中重复的ID删除,再将该重复的放在最前面\n\t\t\t\t\t\t例如:如果获取的cookie值为 1,2,3\n\t\t\t\t\t\t该次访问的pid=2,则拼接完成后应该是2,1,3\n\t\t\t\t\t */\n\t\t\t\t\tString[] pidArr=pids.split("&");\n\t\t\t\t\tList asList = Arrays.asList(pidArr);\n\t\t\t\t\tLinkedList linkedList=new LinkedList<>(asList);\n\t\t\t\t\tlinkedList.remove(pid);\n\t\t\t\t\tlinkedList.addFirst(pid);\n\t\t\t\t\tStringBuffer sb=new StringBuffer();\n\t\t\t\t\tfor(int i=0;i<linkedList.size();i++){\n\t\t\t\t\t\tif(i>0){\n\t\t\t\t\t\t\tsb.append("&");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsb.append(linkedList.get(i));\n\t\t\t\t\t}\n\t\t\t\t\tpids= sb.toString();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tCookie cookie=new Cookie("pids",pids);\n\t\tresp.addCookie(cookie);\n\n\t\treq.getRequestDispatcher("product_info.jsp").forward(req,resp);\n\t}\n\tpublic void addCart(HttpServletRequest req, HttpServletResponse resp){\n\t\ttry{\n\t\t\tString pid=req.getParameter("pid");\n\t\t\tString buyNumStr=req.getParameter("buyNum");\n\t\t\tint buyNum=1;\n\t\t\tif(buyNumStr!=null&&!"".equals(buyNumStr)){\n\t\t\t\tbuyNum=Integer.valueOf(buyNumStr);\n\t\t\t}\n\t\t\tif(buyNum<1){\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tCart cart=(Cart)req.getSession().getAttribute("cart");\n\t\t\tif(cart==null){\n\t\t\t\tProduct product=service.productInfo(pid);\n\t\t\t\tCartItem cartItem=new CartItem(product,buyNum);\n\t\t\t\tMap<String,CartItem> cartItems=new HashMap<>();\n\t\t\t\tcartItems.put(pid,cartItem);\n\t\t\t\tcart =new Cart(cartItems);\n\n\t\t\t}else{\n\t\t\t\tMap<String,CartItem> cartItems=cart.getCartItems();\n\t\t\t\tProduct product = service.productInfo(pid);\n\t\t\t\tCartItem cartItem=cartItems.get(pid);\n\t\t\t\tif(cartItem==null){\n\t\t\t\t\tcartItem=new CartItem(product,buyNum);\n\t\t\t\t\tcartItems.put(pid,cartItem);\n\t\t\t\t\tcart =new Cart(cartItems);\n\t\t\t\t}else{\n\t\t\t\t\tint oldNum=cartItem.getBuyNum();\n\t\t\t\t\tcartItem.setBuyNum( oldNum + buyNum);\n\t\t\t\t\tcartItems.put(pid,cartItem);\n\t\t\t\t}\n\t\t\t\tcart =new Cart(cartItems);\n\t\t\t}\n\t\t\treq.getSession().setAttribute("cart",cart);\n\t\t\tresp.sendRedirect(req.getContextPath()+"/cart.jsp");\n\t\t}catch (Exception e){\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\t//\t删除购物项\n\tpublic void delCart(HttpServletRequest req, HttpServletResponse resp)\n\t\t\tthrows IOException {\n\t\tHttpSession session=req.getSession();\n\t\tCart cart=(Cart)session.getAttribute("cart");\n\t\tif(cart!=null){\n\t\t\tMap<String, CartItem> cartItems = cart.getCartItems();\n\t\t\tString pid=req.getParameter("pid");\n\t\t\tcartItems.remove(pid);\n\t\t\tcart=new Cart(cartItems);\n\t\t\tsession.setAttribute("cart",cart);\n\t\t}\n\t\t\tresp.sendRedirect(req.getContextPath()+"/cart.jsp");\n\t}\n\t//\t清空购物车\n\tpublic void clearCart(HttpServletRequest req, HttpServletResponse resp) {\n\t\tHttpSession session=req.getSession();\n\t\tsession.removeAttribute("cart");\n\t\tSystem.out.println("ProductServlet.clearCart"+session.getAttribute("cart"));\n\t\t//\tresp.sendRedirect(req.getContextPath()+"/cart.jsp");\n\t\ttry {\n\t\t\treq.getRequestDispatcher("/cart.jsp").forward(req,resp);\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\t//\t提交订单\n\tpublic void submitOrder(HttpServletRequest req, HttpServletResponse resp)\n\t\t\tthrows ServletException, IOException {\n\t\tHttpSession session = req.getSession();\n\t\t// 验证用户是否登录\n\t\tUser user = (User) session.getAttribute("user");\n\t\tif (user == null) {\n\t\t\t// 未登录状态\n\t\t\tresp.sendRedirect(req.getContextPath() + "/login.jsp");\n\t\t\treturn;\n\t\t}\n\t\t// 获取购物车\n\t\tCart cart =(Cart) session.getAttribute("cart");\n\t\t// 创建Order对象\n\t\tOrder order = new Order();\n\t\t// 属性封装\n\t\t// 订单编号\n\t\torder.setOid(CommonUtil.generateUUID());\n\t\t// 总金额,从购物车中获取\n\n\t\t// 处理详细逻辑(省略)\n\t\torder.setTotal(cart.getTotal());\n\t\t// 设置购买用户\n\t\torder.setUser(user);\n\n\t\t// 设List orderitems;\n\t\tList orderitems = new ArrayList<>();\n\t\t// 从购物车中获取CartItem转成OrderItem\n\t\tMap<String, CartItem> cartItems = cart.getCartItems();\n\t\tSet keyset= cartItems.keySet();\n\t\tfor (String pid: keyset) {\n\t\t\t// 得到每一个购物项\n\t\t\tCartItem cartItem = cartItems.get(pid);\n\t\t\t// 准备OrderItem,从CartItem转换数据\n\t\t\tOrderItem orderitem = new OrderItem();\n\t\t\t// private String itemid;\n\t\t\torderitem.setItemid(CommonUtil.generateUUID());\n\t\t\t// private int count;//购买的数量\n\t\t\torderitem.setCount(cartItem.getBuyNum());\n\t\t\t// private double subtotal;//小计\n\t\t\torderitem.setSubtotal(cartItem.getSubToal());\n\t\t\t// private Product product;//该项中购买的商品对象\n\t\t\torderitem.setProduct(cartItem.getProduct());\n\t\t\t// private Order order;\n\t\t\torderitem.setOrder(order);\n\t\t\torderitems.add(orderitem);\n\t\t\t// 将订单项存入到order中的订单项的集合中\n\t\t}\n\t\torder.setOrderItems(orderitems);\n\t\tresp.sendRedirect(req.getContextPath() + "/order_info.jsp");\n\t}