首先,我们应该明确,当我们在jsp界面”调用某些实体类的属性”,他并不是真正调用该类的属性,而是调用了该属性的get set方法,举个例子,如下实体类:
import java.util.Date;
public class Student {
private int stuId;
private String stuName;
private int stuAge;
private Date stuBtd;
private int stuSex;
private String stuTel;
private int isDelete;
private String stuSexView;
public String getStuSexView() {
return stuSexView;
}
public void setStuSexView(String stuSexView) {
this.stuSexView = stuSexView;
}
public Student() {
// TODO Auto-generated constructor stub
}
public Student(int stuId, String stuName, int stuAge, Date stuBtd,
int stuSex, String stuTel, int isDelete) {
super();
this.stuId = stuId;
this.stuName = stuName;
this.stuAge = stuAge;
this.stuBtd = stuBtd;
this.stuSex = stuSex;
this.stuTel = stuTel;
this.isDelete = isDelete;
}
public Student(String stuName, int stuAge, Date stuBtd, int stuSex,
String stuTel, int isDelete) {
super();
this.stuName = stuName;
this.stuAge = stuAge;
this.stuBtd = stuBtd;
this.stuSex = stuSex;
this.stuTel = stuTel;
this.isDelete = isDelete;
}
public int getStuId() {
return stuId;
}
public void setStuId(int stuId) {
this.stuId = stuId;
}
public String getStuName() {
return stuName;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
public int getStuAge() {
return stuAge;
}
public void setStuAge(int stuAge) {
this.stuAge = stuAge;
}
public Date getStuBtd() {
return stuBtd;
}
public void setStuBtd(Date stuBtd) {
this.stuBtd = stuBtd;
}
public int getStuSex() {
return stuSex;
}
public void setStuSex(int stuSex) {
this.stuSex = stuSex;
}
public String getStuTel() {
return stuTel;
}
public void setStuTel(String stuTel) {
this.stuTel = stuTel;
}
public int getIsDelete() {
return isDelete;
}
public void setIsDelete(int isDelete) {
this.isDelete = isDelete;
}
@Override
public String toString() {
return "Student [stuId=" + stuId + ", stuName=" + stuName + ", stuAge="
+ stuAge + ", stuBtd=" + stuBtd + ", stuSex=" + stuSex
+ ", stuTel=" + stuTel + ", isDelete=" + isDelete + "]";
}
}
jsp部分代码:
<c:forEach items="${studentList}" var="student">
<tr onmouseover="this.bgColor='gree'" onmouseout="this.bgColor='white'">
<td>${student.stuId}</td>
<td>${student.stuName}</td>
<td>${student.stuAge}</td>
<td>${student.stuBtd}</td>
<td>${student.stuSexView}</td>
<td>${student.stuTel}</td>
<td><a href="${pageContext.request.contextPath}/StudentFindByIdServlet?id=${student.stuId}">更新</a></td>
<td><a href="${pageContext.request.contextPath}/StudentDeleteServlet?id=${student.stuId}" onclick="return confirm('您確定要刪除[${student.stuName}]')">刪除</a></td>
</c:forEach>
这种异常的产生有2种情况(以上面例子为例):
第一种:javax.el.PropertyNotFoundException: Property ‘stuId’ not found on type com.jinzhi.entity.Student
这种情况下,说明你的student实体类中的get/set方法的名字可能与这里的调用的名字不一样(一般情况均为大小写错误),只要你有良好的写代码习惯,第二个单词首字母大写,这种错误一般不会犯!如图:
第二种:javax.el.PropertyNotFoundException: Property ‘stuid’ not found on type java.lang.String
这种情况的出现完全是因为你的粗心大意造成,在foreach中的items属性没有用”${}”将其索要循环的数组括起来,故找不到.如图:
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/96926.html