0

i have just switched from scriptlet to JSTL and now i want to implement a collection to list products from a table but i cant understand the </forEach> in JSTL

code is as follows :- servlet:

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 function :

  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 code :

not sure how to begin here

amol singh
  • 143
  • 1
  • 12
  • You do something like this: http://stackoverflow.com/a/103973/3728901 – Vy Do Aug 02 '15 at 04:48
  • but i am not getting how do i import the collection variable list element `cart` in the jsp code ? – amol singh Aug 02 '15 at 04:52
  • 1
    Your `servelet` is your `controller`, your method named `showCart()` is `model`, JSP file is `view` in MVC model. The passing value from `controller` --> `view` like this: http://stackoverflow.com/a/21540354/3728901 – Vy Do Aug 02 '15 at 04:58
  • @dovy thanks a lot man – amol singh Aug 02 '15 at 05:07

0 Answers0