Results 1 to 2 of 2
  1. #1
    kondiweyane's Avatar
    kondiweyane is offline Member
    Join Date
    Jan 2010
    Location
    Mountain Hua,Xi'AN,China
    Posts
    17
    Rep Power
    0

    Red face spring2.0struts1.2hibernate3.0Demo_bookStore

    SettleAccountsAction.java

    userId doesn't work

    part code:


    public class SettleAccountsAction extends Action {
    private BookBiz bookBiz;

    public void setBookBiz(BookBiz bookBiz) {
    this.bookBiz = bookBiz;
    }

    @SuppressWarnings("unchecked")
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    Map cart = (Map) request.getSession().getAttribute("cart");
    if (cart == null || cart.size() == 0) {
    request.setAttribute("msg", "很抱歉,您没购物");
    return mapping.findForward("succ");
    } else {System.err.println(" ===$$==settleAccounts======¥¥==="+cart);
    int userId = ((UserinfoBean)request.getSession().getAttribute(
    "loginuser")).getUserinfo().getUserId();
    String realname = request.getParameter("loginname");
    String zipcode = request.getParameter("zipcode");
    String phone = request.getParameter("phone");
    String creditcard = request.getParameter("creditcard");
    Set cartItems = cart.keySet();
    Object[] isbn8 = cartItems.toArray();
    int i = 0;
    double total = 0;
    CartItemBean cartItemBean;
    Titles titles8;
    int quantity;
    Double price, subtotal;
    List<CartItemBean> cartItemList = new ArrayList<CartItemBean>();
    while (i < isbn8.length) {
    cartItemBean = (CartItemBean) cart.get(isbn8[i]);
    if (cartItemBean != null) {
    cartItemList.add(cartItemBean);
    }
    titles8 = cartItemBean.getTitles();
    quantity = cartItemBean.getQuantity();
    price = new Double(titles8.getPrice());
    subtotal = quantity * price;
    total += subtotal;
    i++;
    }
    boolean flag = bookBiz.save(userId, realname, zipcode, phone,
    creditcard, total, cartItemList);
    if (flag) {
    request.getSession().removeAttribute("cart");
    request.setAttribute("msg", "结账成功");
    return mapping.findForward("succ");
    } else {
    request.setAttribute("msg", "结账信息有误,请重新结账");
    return mapping.findForward("succ1");
    }
    }
    }
    }



    caused by :java.lang.string can't be cast to com.kang.bean.UserinfoBean


    thanks in advance
    Last edited by kondiweyane; 04-12-2010 at 10:21 AM.

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,087
    Rep Power
    20

    Default

    How do you save the "loginuser"?
    Because that error implies that you're saving it as a String, and not a UserInfoBean.

    Of course, I could be wrong because it's really difficult to read unformatted code...use CODE tags next time please.

Similar Threads

  1. spring2.0struts1.2hibernate3.0Demo_bookStore
    By kondiweyane in forum Web Frameworks
    Replies: 2
    Last Post: 03-23-2010, 07:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •