javax.el.PropertyNotFoundException:在 JSP 中使用 JSTL

发布于 2024-10-01 17:40:39 字数 1222 浏览 3 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

つ可否回来 2024-10-08 17:40:39

您的 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 (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.

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

终止放荡 2024-10-08 17:40:39

如果属性名称以两个或多个连续大写字母开头,那么也应该像在 EL 中一样访问它。因此,要访问 getter getRSSFeedURLs(),您需要 ${rssfom.RSSFeedURLs}

JavaBeans 规范 中也对此进行了指定。

8.8 推断名称的大写。

当我们使用设计模式来推断属性或事件名称时,我们需要决定什么规则
遵循大写推断的名称。如果我们从正常的中间提取名称
混合大小写样式的 Java 名称,则默认情况下该名称将以大写字母开头。
Java 程序员习惯于使用以小写字母开头的普通标识符。
审稿人的积极意见使我们相信我们应该遵循同样的传统规则
用于属性和事件名称。

因此,当我们从现有 Java 名称的中间提取属性或事件名称时,我们
通常将第一个字符转换为小写。 但是支持偶尔使用所有
大写名称,我们检查名称的前两个字符是否都是大写,如果
所以别管它了
。例如,

“FooBah”变成“fooBah”
“Z”变成“z”
“URL”变成“URL”

我们提供了一个方法 Introspector.decapitalize 来实现这个转换规则。

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.

8.8 Capitalization of inferred names.

When we use design patterns to infer a property or event name, we need to decide what rules
to follow for capitalizing the inferred name. If we extract the name from the middle of a normal
mixedCase style Java name then the name will, by default, begin with a capital letter.
Java programmers are accustomed to having normal identifiers start with lower case letters.
Vigorous reviewer input has convinced us that we should follow this same conventional rule
for property and event names.

Thus when we extract a property or event name from the middle of an existing Java name, we
normally convert the first character to lower case. However to support the occasional use of all
upper-case names, we check if the first two characters of the name are both upper case and if
so leave it alone
. So for example,

“FooBah” becomes “fooBah”
“Z” becomes “z”
“URL” becomes “URL”

We provide a method Introspector.decapitalize which implements this conversion rule.

The JSP EL (Expression Language, those ${} things) adheres the JavaBeans Spec. This is thus not specifically related to JSTL (those <c:xxx> tags).

温折酒 2024-10-08 17:40:39

我的 VO 有以下代码

 public class DocumentPolicyVO {
          @JsonProperty("Id")
            private String Id;
            @JsonProperty("Id")
            public String getId() {
                return Id;
            }
     @JsonProperty("Id")
            public void setId(String Id) {
                this.Id = Id;
            }
    }

当我尝试在如下 jsp 页面中访问它时,它给出以下错误 javax.el.PropertyNotFoundException:在 DocumentPolicyVO 类型上找不到属性“Id”

<select name="settingsListExcludingEnvironmentList" class="selectComboboxCheck">
                                                  <c:forEach var="settingsType" items="${settingsListExcludingEnvironmentList}">
                                                      <option value="${settingsType.Id}">${settingsType.Name}</option>
                                                  </c:forEach>
                                        </select>

请任何人都可以解释原因。

My VO has a following code

 public class DocumentPolicyVO {
          @JsonProperty("Id")
            private String Id;
            @JsonProperty("Id")
            public String getId() {
                return Id;
            }
     @JsonProperty("Id")
            public void setId(String Id) {
                this.Id = Id;
            }
    }

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

<select name="settingsListExcludingEnvironmentList" class="selectComboboxCheck">
                                                  <c:forEach var="settingsType" items="${settingsListExcludingEnvironmentList}">
                                                      <option value="${settingsType.Id}">${settingsType.Name}</option>
                                                  </c:forEach>
                                        </select>

Please anybody can explain the reason.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文