1、通过字段, 设置值
package com.chb.struts2Test.action;
public class HelloAction {
private String username;
private String passwd;
public String execute() {
//通过设置属性, 进行传值
this.setUsername("chb");
this.setPasswd("123456");
return "success";
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPasswd() {
return passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
}
2、获取值,
2.1、第一种获取值, 通过 ${property}
获取标签的样式
获取值
public String execute() {
//第二种传值, 通过ActionContext
ActionContext.getContext().put("aaa", "111");
ActionContext.getContext().put("bbb", "222");
return "success";
}
获取值: 结果:
public String execute() {
//第三种传值方式
ServletActionContext.getRequest().setAttribute("hello", "world");
return "success";
}
3.1、如何获取值
在上面案例中, 是从Action向Form传值, 接下来我们将介绍如何从form中向Action传值