| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 860 人关注过本帖
标题:向购物车添加商品出错
取消只看楼主 加入收藏
huanwei50
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-10-31
结帖率:100%
收藏
 问题点数:0 回复次数:0 
向购物车添加商品出错
这是servlet中的代码:
public void shopcar(HttpServletRequest request, HttpServletResponse response)
            throws Exception {
         response.setContentType("text/html;charset=GBK");
         PrintWriter out = response.getWriter();
            
         String strId=request.getParameter("productID");
         int id;
         if(strId==null){
         id=1;
         }else{
         id=Integer.parseInt(strId);
         }
         productservice service=new productservice();
         product products=new product();
         products=service.showproduct(id);
         //String book_number=request.getParameter("book_num");
         //int number;
         //if(book_number==null){
         //number=1;
         //}else{
         //number=Integer.parseInt(book_number);
         //}
         //products.setBook_number(number);
               
         HttpSession s=request.getSession();
         List<product> list;
         if(s.getAttribute("shop")==null){
         list=new ArrayList<product>();
         list.add(products);
         s.setAttribute("shop", list);
         }else {
         list=(List)s.getAttribute("shop");
         list.add(products);
         }
               
         /*RequestDispatcher
         dispatcher=request.getRequestDispatcher("../ShopCart/shopcart.jsp");
         dispatcher.forward(request, response);*/
         HttpSession session =request.getSession();
         session.setAttribute("shop", list);
         response.sendRedirect("../cart/cart.jsp");
         
        out.flush();
        out.close();
    }

这是点击商品上的购买时的代买:
<a href="<%=request.getContextPath()%>/servlet/productServlet?operate=shopCar&productID=<%=products.getProducdID()%>">购买</a>

这是cart.jsp中的代码:
<%
    //int pId=Integer.parseInt(request.getParameter("productID"));
    List<product> proList=(ArrayList)request.getAttribute("proList");
    product pro=new product();
    //productservice ps=new productservice();
    //pro=ps.showproduct(pId);
     %>
 <%
        List<product> shopCar=(ArrayList)session.getAttribute("shopCar");
        product pros=new product();
      %>
  <link rel="stylesheet" href="glCSS/cart.css" type="text/css"></link>

  </head>
  <body>
  <center>
  <div id="tou" >
        <div id="n1" >
        <div id="n2" >
        <div id="z1" >我的购物车</div>
        ............
        <%
                       double sum=0.0;
                       for(int i=0;i<shopCar.size();i++){
                           pros=(product)shopCar.get(i);
                           sum=sum+pros.getProductPrice();
                           %>
        <table border="0" width="1000" height="50" bordercolor="#336699">
           <tr>
              <td width="160"><%=i+1 %></td>
              <td width="160"><%=pros.getProducdID() %></td>
              <td width="160"><%=pros.getProductName() %></td>
              <td width="160"><%=pros.getProductClass() %></td>
              <td width="160"><%=pros.getProductClass() %></td>
           </tr>  
             </table>
             <%} %>
          <br>
         
             <tr>
                <td width="150"></td><td width="150"></td><td width="90">合计总金额:</td><%=sum %><td>¥</td><td width="150"></td>
             </tr>

点击购买后购物车页面显示不出来   要么就是报错   我不知道那错了   帮我改下   谢谢了
搜索更多相关主题的帖子: 购物车 商品 
2010-11-23 18:28
快速回复:向购物车添加商品出错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033024 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved