struts2 中同一个action的实现中对应多个input的处理方法

在struts2中可能会遇到如下的情形:
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

转载于:https://my.oschina.net/thysir/blog/166768

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值