第一种:属性驱动
(1)基本数据类型属性
前端jsp页面的表单的属性名要和java里业务处理Action的属性名匹配,要有get和set方法(不然参数是无法传递到Action中,前端的属性值是通过setter方法注入到Action中)
例子:
前端jsp页面:
body>
<form action=" ">
用户名: <input type="text" name="userName" />
用户密码: <input type="text" name="password" />
<input type="submit" value="提交"/>
</form>
</body>
Action:
public class LoginAction extends ActionSupport{
private String userName;
private String password;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute(){
return " ";
}
}
(2)javaBean形式
前端jsp页面:
body>
<form action=" ">
用户名: <input type="text" name="user.userName" />
用户密码: <input type="text" name="user.password" />
<input type="submit" value="提交"/>
</form>
</body>
Action:
public class LoginAction extends ActionSupport{
private User user;
public User getUser(){
return user;
}
public void setUser(User user) {
this.user = user;
}
public String execute(){
return " ";
}
}
JavaBean
public class User {
private String userName;
private String password;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
模型驱动:ModelDriven
第三种:这种方式不是太常用,只适用于单一请求;
前端jsp页面:
body>
<form action=" ">
用户名: <input type="text" name="userName" />
用户密码: <input type="text" name="password" />
<input type="submit" value="提交"/>
</form>
</body>
Action:
public class LoginAction extends ActionSupport implments ModelDriven<User>{
private User user = new User();
public String execute(){
return " ";
}
public User getModel() {
return this.user;
}
}