struts2中默认拦截器栈中的拦截器…
2015-12-24 10:28
435 查看
1:
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor
While you can configure exception mapping in your
configuration file at any point, the configuration
* will not have any effect if this interceptor is
not in the interceptor stack for your actions.
It is recommended that
* you make this interceptor the first interceptor
on the stack,
ensuring that it has full access to catch
any
* exception, even those caused by other
interceptors.
这句话的意思是你可以配置异常在任何位置,只要这个拦截器没有加入生效的拦截器栈中,该拦截器就不会生效;
官方建议,将异常拦截器配置在拦截器的第一个位置,因为只有这样才能更好的捕获异常,甚至是
其他拦截器发生的异常;
@Override
public
String intercept(ActionInvocation invocation) throws Exception
{
String
result;
try {
result =
invocation.invoke();
} catch
(Exception e) {
if
(isLogEnabled()) {
handleLogging(e);
}
List<ExceptionMappingConfig>
exceptionMappings =
invocation.getProxy().getConfig().getExceptionMappings();
ExceptionMappingConfig mappingConfig =
this.findMappingFromExceptions(exceptionMappings, e);
if
(mappingConfig != null &&
mappingConfig.getResult()!=null) {
Map
parameterMap = mappingConfig.getParams();
// create a
mutable HashMap since some interceptors will remove parameters, and
parameterMap is immutable
invocation.getInvocationContext().setParameters(new
HashMap<String,
Object>(parameterMap));
result =
mappingConfig.getResult();
publishException(invocation, new ExceptionHolder(e));
} else
{
throw
e;
}
}
return
result;
}
这个拦截器的关键代码:
这段代码的意思是,ActionInvocation调用栈中下一个的拦截器或者action对象(统称为元素);
对这个调用进行try catch 捕获;
如果调用这个方法不抛异常,直接将invoke方法的结果返回,回到ActionInvocation中继续执行栈中的下一个元素
(可能是拦截器,也有可能是action类);
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor
While you can configure exception mapping in your
configuration file at any point, the configuration
* will not have any effect if this interceptor is
not in the interceptor stack for your actions.
It is recommended that
* you make this interceptor the first interceptor
on the stack,
ensuring that it has full access to catch
any
* exception, even those caused by other
interceptors.
这句话的意思是你可以配置异常在任何位置,只要这个拦截器没有加入生效的拦截器栈中,该拦截器就不会生效;
官方建议,将异常拦截器配置在拦截器的第一个位置,因为只有这样才能更好的捕获异常,甚至是
其他拦截器发生的异常;
@Override
public
String intercept(ActionInvocation invocation) throws Exception
{
String
result;
try {
result =
invocation.invoke();
} catch
(Exception e) {
if
(isLogEnabled()) {
handleLogging(e);
}
List<ExceptionMappingConfig>
exceptionMappings =
invocation.getProxy().getConfig().getExceptionMappings();
ExceptionMappingConfig mappingConfig =
this.findMappingFromExceptions(exceptionMappings, e);
if
(mappingConfig != null &&
mappingConfig.getResult()!=null) {
Map
parameterMap = mappingConfig.getParams();
// create a
mutable HashMap since some interceptors will remove parameters, and
parameterMap is immutable
invocation.getInvocationContext().setParameters(new
HashMap<String,
Object>(parameterMap));
result =
mappingConfig.getResult();
publishException(invocation, new ExceptionHolder(e));
} else
{
throw
e;
}
}
return
result;
}
这个拦截器的关键代码:
这段代码的意思是,ActionInvocation调用栈中下一个的拦截器或者action对象(统称为元素);
对这个调用进行try catch 捕获;
如果调用这个方法不抛异常,直接将invoke方法的结果返回,回到ActionInvocation中继续执行栈中的下一个元素
(可能是拦截器,也有可能是action类);
相关文章推荐
- Java内存分析(转载)
- Struts2之Action处理多个方法总结
- Spring框架所有技术笔记总结
- JavaWeb基础回顾
- Struts2的笔记整理与复习
- Struts2.3.7技术的汇总之六(权限…
- 黑马程序员--Struts2.3.7技术的汇…
- 黑马程序员--Struts2.3.7技术的汇…
- 黑马程序员--Struts2.3.7技术的汇…
- Struts2.3.7技术的汇总之三(类型…
- Struts2.3.7技术的汇总之二(注册…
- 黑马程序员--Struts2的常量
- 黑马程序员--Struts2复习笔记
- JDK1.5并发库笔记和总结
- Java一些实用的类(持续更新)
- Java多线程基础知识回顾与总结;
- Java基础笔记的复习与整理---Socke…
- Java基础笔记的复习与整理--集合框…
- JDK1.5新特性回顾
- 在学习Java高级应用中碰到的一些问…