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