【问题标题】:JSP/JSTL Error in Eclipse - Undefined attribute nameEclipse 中的 JSP/JSTL 错误 - 未定义的属性名称
【发布时间】:2014-12-15 23:38:26
【问题描述】:

Servlet 代码 sn-p:

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

JSP代码sn-p:

<%@ 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 文件)。有什么建议吗?

【问题讨论】:

  • 编辑你的 foreach 循环 like=

标签: java eclipse jsp jstl taglib


【解决方案1】:

错误信息很清楚:

根据 TLD 对标签 forEach 的属性事务无效

问题出在这里:

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

transactions 更改为items

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

【讨论】:

  • 首先,感谢您编辑我的问题。其次,我已经尝试过您的建议,但无济于事。还有其他想法吗?
  • @JustinHeist 检查您是否在 JSP 的其他部分没有犯过同样的错误。提供您拥有的当前堆栈跟踪。
  • 抱歉,当我有“项目”时,我使用的是不同的 taglib。感谢您的帮助。
猜你喜欢
  • 2015-02-01
  • 1970-01-01
  • 2021-10-04
  • 1970-01-01
  • 2019-05-17
  • 1970-01-01
  • 2018-03-31
  • 1970-01-01
  • 2016-05-18
相关资源
最近更新 更多