我如何实现JSTL集合?

时间:2015-08-02 04:41:32

标签: java jsp jstl

我刚刚从scriptlet切换到JSTL,现在我想实现一个集合来列出表格中的产品,但我无法理解JSTL中的</forEach>

代码如下: - 小服务程序:

public void doGet(HttpServletRequest req , HttpServletResponse res) throws ServletException,IOException
{
    res.setContentType("text/html;charset=UTF-8");
    PrintWriter pw = res.getWriter();
    String n=req.getParameter("action");
     HttpSession ses = req.getSession();
     String userid = ses.getAttribute("uname").toString();
    if(n.equalsIgnoreCase("viewcart"))
    {
       o.showCart(userid); // **i know its incomplete**
    }
 } 

java showCart函数:

  conn = obj.connect();
   String sql="select p.product_name , c.quantity , p.price , c.delivery_time , p.image_url , c.addedtime,c.addeddate"
           + "from cart c inner join product p "
           + "on c.product_id = p.product_id "
           + "inner join register1 r "
           + "on r.userid=c.userid where c.userid='"+userid+"'";
    cs=conn.createStatement();  
   rs=cs.executeQuery(sql);
     while(rs.next())
     {
         product p=new product();
       p.setPname(rs.getString(1));
       p.setQuantity(rs.getString(2));
       p.setPrice(rs.getString(3));
       p.setDtime(rs.getString(4));
       p.setImg(rs.getString(5));

       cart.add(p);  
     }

  }
    catch() 
  return cart;

JSP代码:

not sure how to begin here

0 个答案:

没有答案
相关问题