先上实体类代码的前半部分:
这是出现问题时的:
package com.cheng.pojo;public class People {private int id;private String name;private int age;private String address;public People(int id, String name, int age, String address) {this.id = id;this.name = name;this.age = age;this.address = address;}//getter , setter and toString 略
}
检查了JSP页面也没问题
<jsp:useBean id="people" class="com.cheng.pojo.People" scope="page"/>
<%--等价于People people = new People();--%>
后来发现是没有显式地定义无参构造。因为
定义有参构造后,如果想使用无参构造,必须显式地定义一个无参构造
而且上面JSP代码等价于new People();
已经调用了无参构造,但是我在实体类没有显式写出无参构造。
所以实体类加上无参构造,问题解决
package com.cheng.pojo;public class People {private int id;private String name;private int age;private String address;public People(int id, String name, int age, String address) {this.id = id;this.name = name;this.age = age;this.address = address;}//此情况必须显式定义无参构造!!!!!!!public People() {}//getter , setter and toString 略
}