struts2在拦截器中改变返回的ResultCode
来源:互联网 发布:卫星电视直播软件 编辑:程序博客网 时间:2024/06/10 18:46
1.不执行Action,直接在拦截器中改变返回的ResultCode
package com.zucc.interceptor;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;public class TestInterceptor extends AbstractInterceptor{public TestInterceptor(){System.out.println("TestInterceptor constructor....");}@Overridepublic String intercept(ActionInvocation invocation) throws Exception {System.out.println("TestInterceptor intercept....");return "error";//输入你想返回的ResultCode}}
2.执行Action,通过实现PreResultListener接口来返回ResultCode
先新建接口实现类去实现PreResultListener接口
package com.zucc.interceptor;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.PreResultListener;public class MyPreResultListener implements PreResultListener {/* * 在Action的ResultCode返回之前执行,在这里可以改变ResultCode影响返回的Result */@Overridepublic void beforeResult(ActionInvocation invocation, String resultCode) {// TODO Auto-generated method stubSystem.out.println("MyPreResultListener beforeResult....");invocation.setResultCode("error");//输入你想返回的ResultCode}}
package com.zucc.interceptor;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.Interceptor;public class TestInterceptor extends AbstractInterceptor{private MyPreResultListener prl;public TestInterceptor(){System.out.println("TestInterceptor constructor....");prl = new MyPreResultListener();}@Overridepublic String intercept(ActionInvocation invocation) throws Exception {System.out.println("TestInterceptor intercept....");invocation.addPreResultListener(prl);String resultName = invocation.invoke();return resultName;}}
0 0
- struts2在拦截器中改变返回的ResultCode
- struts2拦截器起作用了,但是返回的登录页面在右侧的mainframe中打开了
- 在Fragment使用startActivityForResult()方法返回的resultCode不正确
- struts2中拦截器的全局拦截和自定义拦截
- struts2中通过拦截器实现对返回结果的过滤
- 【Struts2】Struts2中拦截器
- Struts2中拦截器、过滤器的区别
- Struts2中Interceptor拦截器的使用
- Struts2中execAndWait拦截器的使用
- Struts2的中拦截器总结
- Struts2中拦截器的简单实现
- Struts2中拦截器的配置
- struts2中自定义拦截器的配置
- struts2中拦截器的使用
- 如何在Fragment中拦截webview的返回事件
- android中onActivityResult方法无法获取返回的resultCode和data问题
- android中onActivityResult方法无法获取返回的resultCode和data问题
- if (resultCode == RESULT_OK) 在红米手机上resultCode返回并不是RESULT_OK
- EDK II S3 实现
- 【收藏】Markdown语法说明
- 通过httpUtils请求网络xml数据进行解析
- 《HTTP权威指南》——集成点:网关、隧道、中继
- 【一天一道LeetCode】#108. Convert Sorted Array to Binary Search Tree
- struts2在拦截器中改变返回的ResultCode
- ubuntu linux 命令学习 更改文件权限
- SSH框架下中文乱码问题
- C语言ODBC连接MySQL数据库制作简易用户登录系统
- 解析JSON数据
- Android中 context 和 getApplicationContext()
- Java前台模拟后台数据
- 0622 第六讲操作符重载(2)赋值与==运算符重载
- what's J2EE