public class MyAction extends Action{
public String method1(){
return SUCCESS;
}
public String method2(){
return SUCCESS;
}
}
上 面这段代码包含两个方法method1, method2,并且这两个方法都会受到validate interceptor的影响,会存在校验失败的情况存在,因为struts2中如果校验失败的话会默认的返回到INPUT指定的视图,但情况是我们可能 根据不同的方法返回到不同的视图,这种情况怎么处理呢?
在校验的XML配置中我还真是没有找到处理方法,但可以通过annotation来进行解决。
1、解决办法如下:public class MyAction extends Action{
@InputConfig(resultName="InputresultName1")
public String method1(){
return SUCCESS;
}
// 下面这个的最终结果类似@InputConfig(resultName="method2_input")
@InputConfig(methodName="inputMethodName2")
public String method2(){
return SUCCESS;
}
public String inputMethodName2(){
return "method2_input";
}
}
然后在struts.xml配置文件中添加:
<result name="input">/a.jsp</result><result name="method2_input">/b.jsp</result>
2、原理
之所以通过上面的方式可以解决,主要如下的几个实现
com.opensymphony.xwork2.interceptor.annotations.InputConfig
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor#doIntercept