javax.el.PropertyNotFoundException:在JSP中使用JSTL [英] javax.el.PropertyNotFoundException: using JSTL in JSP

查看:92
本文介绍了javax.el.PropertyNotFoundException:在JSP中使用JSTL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSP,正在尝试使用JSTL标记显示类的内存实例中的数据.数据由一系列字符串组成,其中每个字符串都是RSS提要的地址.

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.

在JSP中,我有以下代码:

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>

基本上,rssfom是以下类的实例:

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();
   }
   ...
}

这继承自RSSFeedMiner类,其中包含以下变量和方法:

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;
}

因此,在JSP中,我认为我可以使用上面的代码,但是当页面运行时,我只是收到一个空表.在服务器日志中,我倾向于找到消息:

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:在类型RSSFeedOccurrenceMiner上找不到属性'rssFeedURLs

javax.el.PropertyNotFoundException: Property 'rssFeedURLs' not found on type RSSFeedOccurrenceMiner

鉴于我对继承的使用,这是正确的.那么谁能告诉我JSTL是否允许继承,或者我的代码中缺少某些内容?

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?

我真的不想在JSP中使用scriptlet.

I really don't want to use a scriptlet in the JSP.

推荐答案

您的getter方法未遵循JavaBeans命名约定.应将其命名为getRssFeedURLs(即使您有首字母缩写词,也应像常规单词一样将其大写).在EL中,当您指定属性名称时,它实际上最终会调用该属性的getter.为了弄清楚吸气剂的名称,它使用您提供的属性名称中的第一个字母大写(因此rssFeedURLs被转换为RssFeedURLs),并在get上添加大写字母.因此,您最终得到getRssFeedURLs.但是,您已将您的方法命名为getRSSFeedURLs. Java无法找到该方法,因此会出现PropertyNotFoundException异常.

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 (so rssFeedURLs gets converted to RssFeedURLs) and tacks on get to the front of it. So you end up with getRssFeedURLs. However, you have named your method as getRSSFeedURLs. Java can't find the method and so you get a PropertyNotFoundException exception.

如果您没有正确命名吸气剂,则无法使用EL对其进行访问.

If you don't name your getters right, you cannot access them with EL.

这篇关于javax.el.PropertyNotFoundException:在JSP中使用JSTL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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