struts2的默认prepare拦截器
来源:互联网 发布:暴漫官方淘宝店是哪个 编辑:程序博客网 时间:2024/06/03 22:49
在struts2的struts-default.xml中定义了一个name为prepare拦截器,实现类是com.opensymphony.xwork2.interceptor.PrepareInterceptor,它的作用是为实现了com.opensymphony.xwork2.Preparable接口的action调用相关方法。该拦截器有两个参数:alwaysInvokePrepare,firstCallPrepareDo,两者的类型都是boolean,默认值分别是true,false。
该拦截器的核心代码如下:
- public String doIntercept(ActionInvocation invocation) throws Exception {
- Object action = invocation.getAction();
- if (action instanceof Preparable) {
- try {
- String[] prefixes;
- if (firstCallPrepareDo) {
- prefixes = new String[] {ALT_PREPARE_PREFIX, PREPARE_PREFIX};
- } else {
- prefixes = new String[] {PREPARE_PREFIX, ALT_PREPARE_PREFIX};
- }
- PrefixMethodInvocationUtil.invokePrefixMethod(invocation, prefixes);
- }
- catch (InvocationTargetException e) {
- /*
- * The invoked method threw an exception and reflection wrapped it
- * in an InvocationTargetException.
- * If possible re-throw the original exception so that normal
- * exception handling will take place.
- */
- Throwable cause = e.getCause();
- if (cause instanceof Exception) {
- throw (Exception) cause;
- } else if(cause instanceof Error) {
- throw (Error) cause;
- } else {
- /*
- * The cause is not an Exception or Error (must be Throwable) so
- * just re-throw the wrapped exception.
- */
- throw e;
- }
- }
- if (alwaysInvokePrepare) {
- ((Preparable) action).prepare();
- }
- }
- return invocation.invoke();
- }
该代码的逻辑非常简单,如果action实现了com.opensymphony.xwork2.Preparable接口,则在调用setXXX和execute()方法之前调用系列方法。如果firstCallPrepareDo为true,则调用prepareDoXXX方法,否则调用prepareXXX方法(XXX为action对应的方法)。接下来查看alwaysInvokePrepare状态,如果其值为true则调用com.opensymphony.xwork2.Preparable接口的prepare方法。最后将action转交给下一个拦截器。
0 0
- struts2的默认prepare拦截器
- struts2默认拦截器之prepare
- struts2修改prepare拦截器
- Struts2拦截器 —— prepare拦截器
- Struts2默认拦截器
- struts2 默认拦截器
- Struts2默认拦截器
- 配置Struts2默认的拦截器
- struts2的拦截器(2):配置默认拦截器
- Struts2默认拦截器说明
- Struts2默认拦截器解析
- Struts2默认拦截器说明
- struts2 默认拦截器解析
- Struts2默认拦截器解析
- Prepare拦截器
- struts2的拦截器自定义,使用默认拦截器,组合拦截器堆 的案例
- struts2拦截器 默认拦截器 默认跳转 全局异常
- Struts2默认拦截器(AliasInterceptor)的使用及源码阅读
- 【Android一般进阶】引用数据类型euqals()与==作用相同
- Leetcode the number of '1' bit
- Linux下程序设计基础
- 如何高效地判断数组中是否包含某特定值
- 递归函数,输入一个非负整数,返回组成它的数字之和。
- struts2的默认prepare拦截器
- MySQL远程访问设置终极方法
- Boosted Tree
- SwipeRefreshLayout组件 自己实现ListView下拉刷新
- LeetCode:Remove Linked List Elements
- NHiberbate使用
- 老版本ubuntu更新原
- JAVA中静态初始化块和非静态初始化块的区别
- 正则表达式的JS验证