action控制器接受jsp传过来的值(方法二)

第二种方法:
使用Domain Model接受参数;
1.先建建一个包,存放实体类;

2.在action中,创建一个user的对象u;

代码如下:

package vo;

public class message {
private int mid;
private String mname;
private int age;
private String mail;
private String address;
private String tel;

private User user;
public int getMid() {
return mid;
}
public void setMid(int mid) {
this.mid = mid;
}
public String getMname() {
return mname;
}
public void setMname(String mname) {
this.mname = mname;
}
@Override
public String toString() {
return "message [mid=" + mid + ", mname=" + mname + ", age=" + age
+ ", mail=" + mail + ", address=" + address + ", tel=" + tel
+ ", user=" + user + "]";
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}

public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}


}


3.在action控制器中类implements ModelDriven<message>

public class messageAction extends ActionSupport implements ModelDriven<message> {

message message=new message();
@Override
public message getModel() {
// TODO Auto-generated method stub
return message;
}

public message getMessage() {
return message;
}
public void setMessage(message message) {
this.message = message;
}

}

4、前台表单提交后 message对象就被实例化了

直接使用就ok了;

posted @ 2016-06-29 14:19  谢坪  阅读(296)  评论(0编辑  收藏  举报