数据库1个字段,在jsp页面 拆成2个输入框的情况
1
User.java
public class User {
private String name;
private String birthday; // 200906
}
2 UserForm.java
public class UserForm extends ActionForm {
private String username;
private String birthday;
//特别说明,在User.jsp界面,把birthday分成2个widget,一个年份,一个月份
//供用户输入,而不是1个widget,但数据库的字段只有1个birthday
private String birthdayYear;//2009
private String birthdayMonth;//06
public void setBirthdayYear(String birthdayYear) {
this.birthdayYear = birthdayYear;
}
public void setBirthdayMonth(String birthdayMonth) {
this.birthdayMonth = birthdayMonth;
}
===================== 底下就不同 =====================
public void setBirthday(String birthday) { //例如birthday = 200906
this.birthdayYear = birthday.subString(0,4); // =2009
this.birthdayMonth = birthday.subString(4,6) // = 06
}
=====================================================
public String getBirthdayYear() {
return birthdayYear;
}
public String getBirthdayMonth() {
return birthdayMonth;
}
===================== 底下就不同 =====================
public String getBirthday() {
return birthdayYear + birthdayMonth; //2009+06
}
=====================================================
}
3 User.jsp
<html:text property="username" />
<html:text property="birthdayYear" />
<html:text property="birthdayMonth"/>
=================说明================================
property会调用getField这个方法,显示结果为getField()这个方法的返回直,而不是
field这个直,
而没有<html property='birthday'/>这个widget在jsp页面,而是分成
年份(birthdayYear),月份(birthdayMonth)为2个输入框,
4
从一个数据库查得的一条记录信息 显示在jsp界面上
比如:
a user record {
username='lu';
birthday='20090613';
}
构造一个UserForm,显示在jsp界面
UserForm userForm = new UserForm();
userForm.setBirthday( user.getBirthday() );
//说明,调用setBirthday(..);会分别给birthdayYear,birthdayMonth赋直
userForm.setUsername(user.getBirthday());
request.getSession().setAttribute("userform",userForm);
5 显示在jsp界面上的1条记录 插入到数据库去
public class SaveAction extends Action {
public ActionForward execute() {
UserForm userForm = (UserForm)actionForm;
User user = new User();
user.setUsername(userForm.getUsername());
user.setBirthday(userForm.getBirthday();)
//说明:userForm.getBirthday() 返回birthdayYear+birthdayMonth
}
}
1
User.java
public class User {
private String name;
private String birthday; // 200906
}
2 UserForm.java
public class UserForm extends ActionForm {
private String username;
private String birthday;
//特别说明,在User.jsp界面,把birthday分成2个widget,一个年份,一个月份
//供用户输入,而不是1个widget,但数据库的字段只有1个birthday
private String birthdayYear;//2009
private String birthdayMonth;//06
public void setBirthdayYear(String birthdayYear) {
this.birthdayYear = birthdayYear;
}
public void setBirthdayMonth(String birthdayMonth) {
this.birthdayMonth = birthdayMonth;
}
===================== 底下就不同 =====================
public void setBirthday(String birthday) { //例如birthday = 200906
this.birthdayYear = birthday.subString(0,4); // =2009
this.birthdayMonth = birthday.subString(4,6) // = 06
}
=====================================================
public String getBirthdayYear() {
return birthdayYear;
}
public String getBirthdayMonth() {
return birthdayMonth;
}
===================== 底下就不同 =====================
public String getBirthday() {
return birthdayYear + birthdayMonth; //2009+06
}
=====================================================
}
3 User.jsp
<html:text property="username" />
<html:text property="birthdayYear" />
<html:text property="birthdayMonth"/>
=================说明================================
property会调用getField这个方法,显示结果为getField()这个方法的返回直,而不是
field这个直,
而没有<html property='birthday'/>这个widget在jsp页面,而是分成
年份(birthdayYear),月份(birthdayMonth)为2个输入框,
4
从一个数据库查得的一条记录信息 显示在jsp界面上
比如:
a user record {
username='lu';
birthday='20090613';
}
构造一个UserForm,显示在jsp界面
UserForm userForm = new UserForm();
userForm.setBirthday( user.getBirthday() );
//说明,调用setBirthday(..);会分别给birthdayYear,birthdayMonth赋直
userForm.setUsername(user.getBirthday());
request.getSession().setAttribute("userform",userForm);
5 显示在jsp界面上的1条记录 插入到数据库去
public class SaveAction extends Action {
public ActionForward execute() {
UserForm userForm = (UserForm)actionForm;
User user = new User();
user.setUsername(userForm.getUsername());
user.setBirthday(userForm.getBirthday();)
//说明:userForm.getBirthday() 返回birthdayYear+birthdayMonth
}
}