【问题标题】:Getting this error using JSTL: javax.el.PropertyNotFoundException使用 JSTL 获取此错误:javax.el.PropertyNotFoundException
【发布时间】:2014-07-18 10:06:59
【问题描述】:

我不明白为什么会出现此错误!我似乎已经为被调用的对象属性建立了正确的命名约定。

我正在将对象列表返回到 .jsp 页面,并尝试遍历列表并使用 JSTL 访问每个属性属性,如下所示:

<h2>Latest Testimonials</h2>
<c:forEach items="${testimonialList}" var="testimonial">
  <p><span class="quote">"${testimonial.getTestimonial}"</span> by ${testimonial.getAuthor</p>
</c:forEach>

这是见证对象:

public class Testimonial {
    private String testimonial, author, date;

    // message get/set
    public String getTestimonial(){
        return testimonial;
    }
    public void setTestimonial(String testimonial){
        this.testimonial = testimonial;
    }

    // name get/set
    public String getAuthor(){
        return author;
    }
    public void setAuthor(String author){
        this.author = author;
    }

    // date get/set
    public String getDate(){
        return date;
    }
    public void setDate(String date){
        this.date = date;
    }
}

完整的错误:

javax.el.PropertyNotFoundException: 属性 'getTestimonial' 不是 在 uk.co.morleys.Testimonial 类型上找到

为什么找不到属性?

【问题讨论】:

    标签: java jsp properties jstl el


    【解决方案1】:

    在此处删除get

    ${testimonial.testimonial}
    

    get 会自动添加。

    【讨论】:

      【解决方案2】:

      试试这个

      <h2>Latest Testimonials</h2>
      <c:forEach items="${testimonialList}" var="testimonial">
            <p><span class="quote">"${testimonial.testimonial}"</span> by ${testimonial.author</p>
      </c:forEach>
      

      【讨论】:

        猜你喜欢
        • 2011-05-06
        • 2013-03-01
        • 1970-01-01
        • 2011-07-16
        • 1970-01-01
        • 1970-01-01
        • 2014-06-30
        • 2012-09-23
        • 1970-01-01
        相关资源
        最近更新 更多