c:forEach 抛出 javax.el.PropertyNotFoundException: Property 'foo'在 java.lang.String 类型上找不到
我的项目使用 hibernate 3.4.0 GA 访问数据库,使用 Spring MVC 2.5.6 处理 Web 请求,使用 jsp(jstl) 渲染视图(网页)。
我通过 hibernate 从数据库获取实体列表,并将其作为模型添加到 jsp 的 modelmap 中。当 jsp 渲染我的网页时,它会抛出“javax.el.PropertyNotFoundException”。
javax.el.PropertyNotFoundException:在 java.lang.String 类型上找不到属性“timestamp”
,异常来自:
<c:forEach var="statusHistory" items="statusHistoryList">
${statusHistory.timestamp}
</c:forEach>
似乎“statusHistory”被视为字符串,而不是对象。
“StatusHistory”类有“timestamp”属性和getter方法:
public Class StatusHistory{
...
private Date timestamp;
public Date getTimestamp(){...}
...
}
我在google上搜索了一整天。有些帖子说 getter 方法不遵循约定。但看来这不是我的情况。
有人可以帮我吗?
提前致谢 安德鲁
My project is using hibernate 3.4.0 GA to access database, and Spring MVC 2.5.6 to handle web request and jsp(jstl) to render view(web page).
I get an entity list from database, by hibernate, and add it as model into modelmap for jsp.When jsp rendering my webpage, it throws a "javax.el.PropertyNotFoundException".
javax.el.PropertyNotFoundException: Property 'timestamp' not found on type java.lang.String
and the exception comes from:
<c:forEach var="statusHistory" items="statusHistoryList">
${statusHistory.timestamp}
</c:forEach>
It seems like that "statusHistory" is considered as a String, but not an object.
The "StatusHistory" class has "timestamp" property and the getter method:
public Class StatusHistory{
...
private Date timestamp;
public Date getTimestamp(){...}
...
}
I have searched on google for one whole day. Some post says that the getter method is not following the convention. But it seems it's not my case.
can some one please help me?
Thanks in advance
Andrew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这里,
您为
的items
属性提供一个值为"statusHistoryList"
的普通字符串,其中反过来确实没有getTimestamp()
方法。您需要使用 EL 表达式
${...}
来引用它。Here,
You're supplying the
items
attribute of<c:forEach>
with a plain vanilla String with a value of"statusHistoryList"
which in turn indeed doesn't have agetTimestamp()
method.You need to reference it using an EL expression
${...}
instead.就我而言,我没有将
implements java.io.Serializable
添加到 bean,因此它无法识别 bean 的属性参考tutorialspoint-JSP
添加后,它解决了问题。
In my case I had not added
implements java.io.Serializable
to the bean so it was not identifying bean's propertyReference tutorialspoint-JSP
Once added it fixed the issue.
保持它就像
确保检查 forEach 循环中的项目有时由于额外的空格它的行为就像一个字符串。尝试重新输入。
Keep it like
Make sure to check items in forEach loop sometimes it acts like a string due to an extra space. Try retyping it.