将对象添加到ArrayList后,我的程序停止运行

时间:2019-05-09 13:51:05

标签: java arrays list servlets arraylist

protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Shoppingcart cart = new Shoppingcart();
    List<Shoppingcart> cartList = (List<Shoppingcart>)request.getAttribute("cartList");
    Object obj = new Object();
    cart.setMovie(request.getParameter("name"));
    cart.setPrice(Double.parseDouble(request.getParameter("price")));
    cart.setQuantity(Integer.parseInt(request.getParameter("qty")));
    cart.setRating(request.getParameter("rate"));
    cart.setYearcreate(request.getParameter("year"));
    cartList.add(cart);
    request.setAttribute("cartList", cartList);
    // ShoppingcartDao.insertShoppingcart(cart);
    // request.getRequestDispatcher("cartList.jsp").include(request, response);
}

当程序到达cartList.add(cart);时,它返回此方法的第一行;当到达cartList.add(cart);时,它将跳过request.setAttribute("cartList", cartList);并停止。

如何修复程序以继续request.setAttribute("cartList", cartList);

0 个答案:

没有答案