c:forEach 抛出 javax.el.PropertyNotFoundException: 在类型 java.lang.String 上找不到属性“foo" [英] c:forEach throws javax.el.PropertyNotFoundException: Property 'foo' not found on type java.lang.String

查看:30
本文介绍了c:forEach 抛出 javax.el.PropertyNotFoundException: 在类型 java.lang.String 上找不到属性“foo"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目使用 hibernate 3.4.0 GA 来访问数据库,使用 Spring MVC 2.5.6 来处理 web 请求和 jsp(jstl) 来呈现视图(网页).

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).

我通过休眠从数据库中获取实体列表,并将其作为模型添加到 jsp 的模型映射中.当 jsp 呈现我的网页时,它会抛出javax.el.PropertyNotFoundException".

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:在类型 java.lang.String 上找不到属性时间戳"

javax.el.PropertyNotFoundException: Property 'timestamp' not found on type java.lang.String

异常来自:

<c:forEach var="statusHistory" items="statusHistoryList">
    ${statusHistory.timestamp}
</c:forEach>

似乎statusHistory"被认为是一个字符串,而不是一个对象.

It seems like that "statusHistory" is considered as a String, but not an object.

StatusHistory"类具有timestamp"属性和getter方法:

The "StatusHistory" class has "timestamp" property and the getter method:

public Class StatusHistory{
    ...
    private Date timestamp;
    public Date getTimestamp(){...}
    ...
}

我在谷歌上搜索了一整天.一些帖子说 getter 方法不遵循约定.但似乎不是我的情况.
有人可以帮我吗?

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?

提前致谢安德鲁

推荐答案

这里,

<c:forEach var="statusHistory" items="statusHistoryList">

您正在为 <c:forEach>items 属性提供一个值为 "statusHistoryList" 的普通字符串反过来,它确实没有 getTimestamp() 方法.

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.

您需要使用 EL 表达式 ${...} 来引用它.

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

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆