区别在于Action和JSP
Action:
package com.example.struts;
import com.example.struts.domain.User;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ModelDriven;
public class UserModelAction implements Action, ModelDriven<User> {
// 必须手动实例化
private User user = new User();
private String code;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
@Override
public String execute() throws Exception {
System.out.println(user);
System.out.println(code);
return NONE;
}
@Override
public User getModel() {
return user;
}
}
jsp:
<h2>模型驱动</h2>
<form method="post" action="${ pageContext.request.contextPath }/user/add2">
<input type="text" name="username" />
<input type="password" name="password" />
<input type="number" name="age" />
<input type="date" name="date" />
<input type="text" name="code" />
<button type="submit">提交</button>
</form>
来源:oschina
链接:https://my.oschina.net/u/3870422/blog/4313104