javax.el.PropertyNotFoundException:在 JSP 中使用 JSTL
我有一个 JSP,我尝试使用 JSTL 标记来显示类的内存实例中的数据。该数据由一系列字符串组成,其中每个字符串都是 RSS 提要的地址。
在JSP中,我有以下代码:
<table border = "1">
<tr>
<c:forEach var = "rssFeedURL" items = "${rssfom.rssFeedURLs}">
<td align = "left">${rssFeedURL}</td>
</c:forEach>
</tr>
</table>
基本上,rssfom是以下类的实例:
public class RSSFeedOccurrenceMiner extends RSSFeedMiner {
private HashMap<String, Counter> keywordFrequencies;
public RSS_Feed_OccurrenceMiner() {
super();
this.keywordFrequencies = new HashMap();
}
...
}
它继承自类RSSFeedMiner,其中包含以下变量和方法:
private ArrayList<String> rssFeedURLs;
public ArrayList<String> getRSSFeedURLs() {
return rssFeedURLs;
}
public void setRSSFeedURLs(ArrayList<String> rssFeedURLs) {
this.rssFeedURLs = rssFeedURLs;
}
所以在JSP中,我想我可以使用上面的代码但是当页面运行时,我只是收到一个空表。在服务器日志中,我倾向于找到消息:
javax.el.PropertyNotFoundException:在 RSSFeedOccurrenceMiner 类型上找不到属性“rssFeedURLs”
鉴于我使用继承,这是正确的。那么谁能告诉我 JSTL 是否允许继承或者我的代码中是否缺少某些内容?
我真的不想在 JSP 中使用 scriptlet。
I have a JSP where I'm trying to use JSTL tags to display data from an in-memory instance of a class. The data consists of a series of Strings where each String is the address of an RSS feed.
In the JSP, I have the following code:
<table border = "1">
<tr>
<c:forEach var = "rssFeedURL" items = "${rssfom.rssFeedURLs}">
<td align = "left">${rssFeedURL}</td>
</c:forEach>
</tr>
</table>
Basically, rssfom is an instance of the following class:
public class RSSFeedOccurrenceMiner extends RSSFeedMiner {
private HashMap<String, Counter> keywordFrequencies;
public RSS_Feed_OccurrenceMiner() {
super();
this.keywordFrequencies = new HashMap();
}
...
}
This inherits from class RSSFeedMiner which contains the following variable and methods:
private ArrayList<String> rssFeedURLs;
public ArrayList<String> getRSSFeedURLs() {
return rssFeedURLs;
}
public void setRSSFeedURLs(ArrayList<String> rssFeedURLs) {
this.rssFeedURLs = rssFeedURLs;
}
So in the JSP, I thought I would be able to use the code above but when the page is run, I simply receive an empty table. And in the server logs, I tend to find message:
javax.el.PropertyNotFoundException: Property 'rssFeedURLs' not found on type RSSFeedOccurrenceMiner
Which is correct given my use of inheritance. So can anyone tell me if JSTL allows inheritance or is there something missing in my code?
I really don't want to use a scriptlet in the JSP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的 getter 方法不遵循 JavaBeans 命名约定。它应该命名为
getRssFeedURLs
(即使您有缩写词,也应该像普通单词一样大写)。在 EL 中,当您指定属性名称时,它实际上最终会调用该属性的 getter。为了找出 getter 的名称,它将您提供的属性名称中的第一个字母大写(因此 rssFeedURLs 会转换为 RssFeedURLs )并添加到达它的前面。所以你最终会得到
getRssFeedURLs
。但是,您已将方法命名为getRSSFeedURLs
。 Java 找不到该方法,因此您会收到PropertyNotFoundException
异常。如果您没有正确命名 getter,则无法使用 EL 访问它们。
Your getter method doesn't follow the JavaBeans naming convention. It should be named
getRssFeedURLs
(even if you have an acronym, it should be capitalized like a regular word). In EL, when you specify a property name, it actually ends up calling the getter for that property. To figure out the name of the getter, it capitalizes the first letter in the property name that you have provided (sorssFeedURLs
gets converted toRssFeedURLs
) and tacks onget
to the front of it. So you end up withgetRssFeedURLs
. However, you have named your method asgetRSSFeedURLs
. Java can't find the method and so you get aPropertyNotFoundException
exception.If you don't name your getters right, you cannot access them with EL.
如果属性名称以两个或多个连续大写字母开头,那么也应该像在 EL 中一样访问它。因此,要访问 getter
getRSSFeedURLs()
,您需要${rssfom.RSSFeedURLs}
。JavaBeans 规范 中也对此进行了指定。
JSP EL(表达式语言,那些
${}
的东西)遵守 JavaBeans 规范。因此,这与 JSTL(那些
标签)没有具体关系。If the property name starts with two or more subsequent capitals, then it should be accessed like that in EL as well. So, to access the getter
getRSSFeedURLs()
you need${rssfom.RSSFeedURLs}
.That's specified in JavaBeans Spec as well.
The JSP EL (Expression Language, those
${}
things) adheres the JavaBeans Spec. This is thus not specifically related to JSTL (those<c:xxx>
tags).我的 VO 有以下代码
当我尝试在如下 jsp 页面中访问它时,它给出以下错误 javax.el.PropertyNotFoundException:在 DocumentPolicyVO 类型上找不到属性“Id”
请任何人都可以解释原因。
My VO has a following code
When I am trying to access it in a jsp page as below, it is giving following error javax.el.PropertyNotFoundException: Property 'Id' not found on type DocumentPolicyVO
Please anybody can explain the reason.