c:forEach抛出javax.el.PropertyNotFoundException:在java.lang.String类型中找不到属性'foo' [英] c:forEach throws javax.el.PropertyNotFoundException: Property 'foo' not found on type java.lang.String
问题描述
我从数据库中获取一个实体列表,并将其作为模型添加到jsp的模型图中。当jsp渲染我的网页时,它抛出一个javax.el.PropertyNotFoundException。
javax.el.PropertyNotFoundException:在类型java.lang.String中找不到属性'timestamp'
$
< c:forEach var =statusHistoryitems =statusHistoryList >
$ {statusHistory.timestamp}
< / c:forEach>
看起来像statusHistory被认为是一个字符串,而不是一个对象。 >
StatusHistory类具有timestamp属性和getter方法:
公共类StatusHistory {
...
私人日期时间戳;
public Date getTimestamp(){...}
...
}
我在谷歌搜索了一整天。有些文章说getter方法不符合约定。但似乎不是我的情况。
可以有人请帮助我吗?
预先感谢
Andrew
在这里,
< c:forEach var =statusHistoryitems =statusHistoryList>
您正在提供 你需要引用它EL表达式 / code>属性
< c:forEach>
用普通的香草字符串,值为statusHistoryList
它确实没有一个 getTimestamp()
方法。
$ {...}
来代替。 c:forEach var =statusHistoryitems =$ {statusHistoryList}>
$ {statusHistory.timestamp}
< / c:forEach>
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
Here,
<c:forEach var="statusHistory" items="statusHistoryList">
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 a getTimestamp()
method.
You need to reference it using an EL expression ${...}
instead.
<c:forEach var="statusHistory" items="${statusHistoryList}">
${statusHistory.timestamp}
</c:forEach>
这篇关于c:forEach抛出javax.el.PropertyNotFoundException:在java.lang.String类型中找不到属性'foo'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!