I see two problems with the code you posted:
1 - the case for cart
is wrong. In the following code you must have Cart
with a capital C:
<c:forEach items="${Cart}" var="current">
Also, this code
...
<% ArrayList cart=(ArrayList)session.getAttribute("Cart");
out.println(cart);
//this line is working
%>
...
<c:forEach items="${cart}" var="current">
does not pick up the cart
variable you created with the scriptlet (if that's what you are thinking). cart
is a local variable in the servlet generated from your JSP. The tag won't be able to access it).
2 - where is the taglib declaration for your c:forEach
tag? Something like:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
If the server does not recognize the tag as what it is, it will output the thing directly into the response. Your browser won't recognize <c:forEach>
and will ignore it (i.e. you have it in the source code but it is not displayed on the screen).
Use the following code for your JSP and it should work:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>my cart</title>
</head>
<body>
<table>
<tr bgcolor="#EAEAFF">
<td><b>Product ID</b></td>
</tr>
<c:forEach items="${Cart}" var="current">
<tr>
<td><c:out value="${current}" /></td>
</tr>
</c:forEach>
</table>
</body>
</html>