概述
需要实现 com.opensymphony.xwork2.Preparable接口,继承ActionSupport类:
public class OrderActionMethod extends ActionSupport implements Preparable {
private String username;
@Override
public void prepare() throws Exception {
System.out.println(" method prepare start ... ");
}
@Override
public String execute() throws Exception {
System.out.println(" method execute start ... ");
return SUCCESS;
}
@Override
public void validate() {
System.out.println(" method validate start ... ");
}
public String prepareAddUser(){
System.out.println(" method prepareaAddUser start ... ");
return SUCCESS;
}
public String validateAddUser(){
System.out.println(" method validateAddUser start ... ");
return SUCCESS;
}
public String addUser(){
System.out.println(" method addUser start ... ");
return SUCCESS;
}
public String getUsername() {
System.out.println(" method getUsername start ... ");
return username;
}
public void setUsername(String username) {
System.out.println(" method setUsername start ... ");
this.username = username;
}
}
1、按照上面的执行addUser顺序为:
10:21:30,695 INFO [STDOUT] method prepareaAddUser start ...
10:21:30,695 INFO [STDOUT] method prepare start ...
10:21:30,695 INFO [STDOUT] method setUsername start ...
10:21:30,696 INFO [STDOUT] method validateAddUser start ...
10:21:30,696 INFO [STDOUT] method validate start ...
10:21:30,696 INFO [STDOUT] method addUser start ...
从结果可以 prepare方法名方法 --> prepare方法 -->set方法--> validate方法名方法 -->validate方法--> 方法;
2、请求执行execute默认方法或执行 localhost:8080//manage/orderActionMethod.action?username=s(也就是没有指定要执行的方法):
10:59:52,706 INFO [STDOUT] method prepare start ...
10:59:52,706 INFO [STDOUT] method setUsername start ...
10:59:52,706 INFO [STDOUT] method validate start ...
10:59:52,706 INFO [STDOUT] method execute start ...
转载于:https://www.cnblogs.com/lbangel/archive/2013/05/23/3094474.html
最后
以上就是老实小熊猫为你收集整理的struts2的action方法执行顺序 Preparable的全部内容,希望文章能够帮你解决struts2的action方法执行顺序 Preparable所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复