0
我正在尝试熟悉Struts 1,因为它仍在我们当前的项目中使用。在创建一个简单的数据录入应用程序时,我遇到了一个例外情况:如何检索struts表单中的关联属性
javax.servlet.jsp.JspException:异常的getter方法 物业抛出:bean的 “城市”: “studentForm”
- 是否有Struts的HTML表单访问的方式地址字段;城市和省?
- Struts HTML表单属性标签是否只接受字符串数据类型?
Person.class
@MappedSuperclass
public abstract class Person implements Serializable {
static SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/yyyy");
@Column(name = "first_name", nullable = false, updatable = true, insertable = true)
private String firstName;
@Column(name = "last_name", nullable = false, updatable = true, insertable = true)
private String lastName;
@Column(name = "date_of_birth", nullable = false, updatable = true, insertable = true)
@Temporal(TemporalType.DATE)
private String dateOfBirth;
@Embedded
private Address address;
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
Address类
@Embeddable
public class Address {
@Column(name = "city", nullable = false, updatable = true, insertable = true)
private String city;
@Column(name = "province", nullable = false, updatable = true, insertable = true)
private String province;
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city.toUpperCase();
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province.toUpperCase();
}
助学行动形式
public class StudentForm extends ActionForm {
private StudentBean student = new StudentBean();
private Address address = new Address();
public Address getAddress() {
return student.getAddress();
}
public void setAddress(Address address) {
this.student.setAddress(address);
}
public String getCity() {
return student.getAddress().getCity();
}
public void setCity(String city) {
this.student.getAddress().setCity(city);
}
public String getProvince() {
return student.getAddress().getProvince();
}
public void setProvince(String province) {
this.student.getAddress().setProvince(province);
}
的Struts 1 HTML表单
<html:form action="RegisterStudent.do">
<label for="firstName">First Name: </label>
<html:text name="studentForm" property="firstName" />
<br>
<label for="lastName">Last Name: </label>
<html:text name="studentForm" property="lastName" />
<br>
<label for="dateOfBirth">Date of Birth(mm/dd/yyyy): </label>
<html:text name="studentForm" property="dateOfBirth" />
<br>
<label for="city">City: </label>
<html:text name="studentForm" property="city" />
<br>
<label for="province">Province: </label>
<html:text name="studentForm" property="province" />
<br>
<label for="department">School Department: </label>
<html:text name="studentForm" property="department" />
<br>
<html:submit>Register</html:submit>
</html:form>