我的代码中遇到属性未找到异常的问题。我已经遵循了公共getter和setter的正确命名约定,但仍然收到异常,我不知道为什么。我搜索了一个解决方案,没有发布高低。我究竟做错了什么?可能是我正在访问列表吗?
Java class Book:
public class Book {
private String isbn13; // International Standard Book Number, unique
private String title;
private String author;
private LocalDate publishDate; // Date of publish to the website
private double price;
private byte[] content;
private ArrayList<String> tagList;
public ArrayList<String> getTagList() {
return tagList;
}
public void setTagList(ArrayList<String> tagList) {
this.tagList = tagList;
}
// Constructor used when no date is specified
public Book(String isbn, String title, String author, byte[] content) {
this.isbn13 = isbn;
this.title = title;
this.author = author;
this.publishDate = LocalDate.now();
this.content = content;
}
// Constructor used when a date is specified
public Book(String isbn, String title, String author, byte[] content, LocalDate publishDate) {
this.isbn13 = isbn;
this.title = title;
this.author = author;
this.publishDate = publishDate;
this.content = content;
}
// Default constructor
public Book() {
this.isbn13 = null;
this.title = null;
this.author = null;
this.publishDate = LocalDate.now();
this.content = null;
}
public String getIsbn13() {
return isbn13;
}
public void setIsbn13(String isbn13) {
this.isbn13 = isbn13;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public LocalDate getPublishDate() {
return publishDate;
}
public void setPublishDate(LocalDate publishDate) {
this.publishDate = publishDate;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public byte[] getContent() {
return content;
}
public void setContent(byte[] content) {
this.content = content;
}
}
来自.jsp文件的代码
<c:forEach var="tag" items="${book.tagList}">
<c:out value="${tag}" />
</c:forEach>
抛出异常:
org.apache.jasper.JasperException:
org.apache.jasper.el.JspPropertyNotFoundException:
/bookPublishingHome.jsp(50,10) '${book.tagList}' The class
'examples.pubhub.model.Book' does not have the property 'tagList'.