伪墨 2017-04-10 02:27 采纳率: 33.3%
浏览 1884
已采纳

购物车显示商品总额,点击结算扣除账户金额

我通过foreach显示每个商品详情,该怎么显示总额并且把它传给action?图片说明)

  • 写回答

3条回答 默认 最新

  • 傻瓜先生DIM 2019-04-23 19:44
    关注

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Map<String,Integer> shopcar = (Map<String,Integer>)request.getSession().getAttribute("shopcar");
        Set<String> isbns = shopcar.keySet();
        for(String isbn : isbns){
            String value = request.getParameter(isbn);
            shopcar.put(isbn, Integer.parseInt(value));    //更新购物车中的购买数量          
        }
        UserBiz biz = new UserBiz();
    
        try {
    
            List<TBook> books = null;
            if(shopcar.keySet().size()>0){
                books = biz.getShopcarData(shopcar.keySet());
            }
            double allPrice = 0;
            for(TBook bk : books){
                int buyCount = shopcar.get(bk.getIsbn());
                bk.setBuyCount(buyCount);          //设置图书数量
                allPrice = allPrice + bk.getPrice()*buyCount;
            }
            request.setAttribute("allPrice", allPrice);
            request.setAttribute("books", books);               
            request.getRequestDispatcher("/main/checkout.jsp").forward(request, response);          
        } catch (Exception e) {
            Log.logger.error(e.getMessage(),e);
            request.setAttribute("msg", "网络异常,请和管理员联系");
            request.getRequestDispatcher("/err/error.jsp").forward(request,response);
        }
    }
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 对接美团闪购医药接口相关问题
  • ¥15 嵌入式软件电子烟开发
  • ¥15 职场 Excel 查重问题
  • ¥20 multisim方波发生电路产生的波形异常,学校没讲模电就留了实验qwq
  • ¥15 求怎么用idea2021.3.2创建web项目并配置tomcat
  • ¥100 or-tools的相关问题
  • ¥15 有可能用平板通过拓展坞来烧录程序吗(keil5的那种)
  • ¥15 状态图的并发态问题咨询
  • ¥15 PFC3D,plot
  • ¥15 VAE模型编程报错无法解决