我不明白为什么会收到此错误!我似乎已经为正在调用的对象属性建立了正确的命名约定。
我正在将对象列表返回到 .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: Property 'getTestimonial' not found on type uk.co.morleys.Testimonial
为什么找不到该属性?
最佳答案
删除此处的get
:
${testimonial.testimonial}
get会自动添加。
关于java - 使用 JSTL 出现此错误 : javax. el.PropertyNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24822426/