有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Eclipse未定义属性名中的java JSP/JSTL错误

Servlet代码片段:

// check/get session
    HttpSession session = request.getSession();
    ArrayList<LineItem> transactions = (ArrayList<LineItem>)session.getAttribute("transactions");
.....
// set session
session.setAttribute("transactions", transactions);

JSP代码片段:

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
.....
<c:forEach var="item" transactions="${transactions}">  
            <tr>
                <td>${item.action}</td>
                <td>${item.product.getCode}</td>
                <td>${item.product.getArtist}</td>
                <td>${item.product.getTitle}</td>
                <td>${item.product.getCategory}</td>
                <td>${item.product.getDescription}</td>
                <td>${item.product.getPriceCurrency}</td>
            </tr>
 </c:forEach>

例外情况:

SEVERE: Servlet.service() for servlet [jsp] in context with path [/Maintenance] threw exception [/product_audit.jsp (line: 52, column: 4) Attribute transactions invalid for tag forEach according to TLD] with root cause
org.apache.jasper.JasperException: /product_audit.jsp (line: 52, column: 4) Attribute transactions invalid for tag forEach according to TLD

我使用的是JSTL 1.0(在清单中声明并验证了.jar文件)。有什么建议吗


共 (1) 个答案

  1. # 1 楼答案

    错误信息很清楚:

    Attribute transactions invalid for tag forEach according to TLD

    问题在于:

    <c:forEach var="item" transactions="${transactions}">
    <!                   ^ there is no such attribute  >
    

    transactions更改为items

    <c:forEach var="item" items="${transactions}">