0

I am working on a project with java servlets and JSP.

I have a java class that generates me a list of products, of type List<Product> and I saved the list in variable Products.

Ex:  List<Product> products = ProductIO.selectProducts();

To access the name description of each list I use. (print them to screen)

System.out.println(products.get(i).getDescription());

Okay! Now here comes the problem, I want to generate a table and place all items descriptions in there, However I get a blank table and I assume is bad syntax.

Here is my products.jsp code.

<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="utf-8">
    <title>Murach's Java Servlets and JSP</title>
    <link rel="stylesheet" href="styles/main.css" type="text/css"/>
</head>
<body>
<h1>CD list</h1>
<table>
    <tr>
        <th>Description</th>
        <th>&nbsp;</th>
    </tr>        
    <c:forEach var="product" items="${products}" varStatus ="i">
    <tr>
        <td><c:out value='${product.get(i).getDescription}' /></td>
    </tr>
    </c:forEach>
</table>
</body>
</html>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Gui Costa
  • 1
  • 5

1 Answers1

1

EDITED

p_IO.selectProducts() may be a List<Product> so you don't need to extract list within forEach. Try this:

....
<c:forEach items="${p_IO.selectProducts()}" var="product" >
    <tr>
        <td><c:out value='${product.description}' /></td>
    </tr>
</c:forEach>
....
auntyellow
  • 2,423
  • 2
  • 20
  • 47