struts2 中同一个action的实现中对应多个input的处理方法
来源:互联网 发布:c标签和js函数 编辑:程序博客网 时间:2024/06/07 19:23
在struts2中可能会遇到如下的情形:
Java代码
public class MyAction extends Action{
public String method1(){
return SUCCESS;
}
public String method2(){
return SUCCESS;
}
}
上面这段代码包含两个方法method1, method2,并且这两个方法都会受到validate interceptor的影响,会存在校验失败的情况存在,因为struts2中如果校验失败的话会默认的返回到INPUT指定的视图,但情况是我们可能根据不同的方法返回到不同的视图,这种情况怎么处理呢?在校验的XML配置中我还真是没有找到处理方法,但可以通过annotation来进行解决。
1、解决办法如下:
Java代码
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";
}
}
Java代码
public class MyAction extends Action{
public String method1(){
return SUCCESS;
}
public String method2(){
return SUCCESS;
}
}
public class MyAction extends Action{ public String method1(){ return SUCCESS; } public String method2(){ return SUCCESS; } }
上面这段代码包含两个方法method1, method2,并且这两个方法都会受到validate interceptor的影响,会存在校验失败的情况存在,因为struts2中如果校验失败的话会默认的返回到INPUT指定的视图,但情况是我们可能根据不同的方法返回到不同的视图,这种情况怎么处理呢?在校验的XML配置中我还真是没有找到处理方法,但可以通过annotation来进行解决。
1、解决办法如下:
Java代码
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";
}
}
public class MyAction extends Action{ public String method1(){ return SUCCESS; } // 下面这个的最终结果类似@InputConfig(resultName="method2_input") @InputConfig(methodName="inputMethodName") public String method2(){ return SUCCESS; } public String inputMethodName(){ 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
- struts2 中同一个action的实现中对应多个input的处理方法
- Struts2中一个Action多个请求处理方法的三种实现方式
- Struts2中一个Action多个请求处理方法的三种实现方式
- struts2 的一个action中配置多个result input
- 对struts2中action的多个方法进行校验
- 在struts1中使用DispatchAction对应多个ActionForm,实现写一个Action实现增删改查操作---一个Action处理多个操作的能力
- 【转】struts2中处理同一个表单的多个提交按钮
- Struts2一个action处理多个方法的语法格式
- 动态方法调用 在Struts2中动态方法调用有三种方式,动态方法调用就是为了解决一个Action对应多个请求的处理,以免Action太多 第一种方式:指定method属性 这种方式我们前面已经用到过
- Struts2中Action接收参数的方法
- Struts2中Action接收参数的方法
- 改变struts2中action后缀的方法
- Struts2中Action接收参数的方法
- struts2的action中方法重复执行
- Struts2中Action接收参数的方法
- struts2中action接收参数的方法
- struts2中action接收参数的方法
- struts2中action接收参数的方法
- Linux下快速搭建SVN服务管理项目源代码
- INPUT
- 信号量sem
- 最简化的DirectX 11开发环境的配置
- 虚拟摄像头驱动原理及开发
- struts2 中同一个action的实现中对应多个input的处理方法
- 进步了!
- 在GitHub上分享和展示你的代码
- fortran大型数组的二进制存储-matlab读取
- hibernate3中出现 could not initialize proxy - no Session 错误的解决办法以及lazy load的介绍
- EasyUI Tree+Asp.net实现权限树或目录树导航
- 关于platform_device和platform_driver的匹配
- 联合查询与多表查询基础详解
- hdu1355 The Peanuts