Struts2拦截器 —— prepare拦截器
2013-11-06 14:47
477 查看
实现类
com.opensymphony.xwork2.interceptor.PrepareInterceptor
作用
为实现了com.opensymphony.xwork2.Preparable接口的action调用相关方法。
两个参数
关键源码
执行顺序
在struts2中,如果Action实现了Prepare接口:
prepare<方法名>()
--> prepare() --> validate<方法名>方法
--> execute方法
com.opensymphony.xwork2.interceptor.PrepareInterceptor
作用
为实现了com.opensymphony.xwork2.Preparable接口的action调用相关方法。
两个参数
参数名 | 值类型 | 默认值 | 描述 |
alwaysInvokePrepare | boolean | true | 如果其值为true则调用接口定义的prepare方法。 |
firstCallPrepareDo | boolean | false | 如果值为true,则调用prepareDoXXX方法。 否则调用prepareXXX方法(XXX为action对应的方法)。 |
关键源码
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(); } |
执行顺序
在struts2中,如果Action实现了Prepare接口:
prepare<方法名>()
--> prepare() --> validate<方法名>方法
--> execute方法
相关文章推荐
- struts2 jquery 打造无限层次的树
- ajax交互Struts2的action(客户端/服务器端)
- struts2 spring整合fieldError问题
- Struts2的s:radio标签使用及用jquery添加change事件
- Struts2访问servlet分享
- Java(基于Struts2) 分页实现代码
- 从搭建Struts2 开发环境说起
- 关于国际化、OGNL表达式语言
- 在Struts2中如何将父类属性序列化为JSON格式的解决方法
- 在Struts2中的结果集类型
- 关于Struts2的类型转换详解
- 搭建EXTJS和STRUTS2框架(ext和struts2简单实例)
- 关于Struts2文件上传与自定义拦截器
- JavaWeb中struts2实现文件上传下载功能实例解析
- Struts2的学习笔记(2)
- Struts2的学习笔记(3)
- Struts2的学习笔记(4)
- iterator 标签的使用
- struts2注解配置注意事项
- 使用open flash chart制作报表