Jsp不会显示包含内容的表

时间:2016-10-03 15:38:46

标签: jsp servlets

我正在研究一个带有java servlets和JSP的项目。

我有一个java类,它生成了List<Product>类型的产品列表,并将列表保存在变量Products中。

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

访问我使用的每个列表的名称描述。 (将它们打印到屏幕上)

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

好!现在问题来了,我想生成一个表并将所有项目描述放在那里,但是我得到一个空白表,我认为是错误的语法。

这是我的products.jsp代码。

<!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>

1 个答案:

答案 0 :(得分:1)

<强> EDITED

p_IO.selectProducts()可能是List<Product>,因此您无需在forEach中提取列表。试试这个:

....
<c:forEach items="${p_IO.selectProducts()}" var="product" >
    <tr>
        <td><c:out value='${product.description}' /></td>
    </tr>
</c:forEach>
....
相关问题