Struts 2 mapping interceptors to action
2015-09-15 16:16
246 查看
Struts 2 developers are used to declare the actions belong to a package that extend the “
The default set of interceptors are grouped as “
In above snippet code, it map the “
The interceptors will fire in the order they’re declared.
Since the “
struts-default“, which contains the default set of interceptors.
<package name="default" namespace="/" extends="struts-default"> <action name="testingAction" class="com.mkyong.common.action.TestingAction" > <result name="success">pages/result.jsp</result> </action> </package>
The default set of interceptors are grouped as “
defaultStack” in
struts-default.xmlfile, which is located in the
struts2-core.jarfile. The “
defaultStack” provides all the core Struts 2 functionality, which is suit the need of most application.
Mapping interceptor to action
To map other interceptors to action, use the “interceptor-ref” element.
<package name="default" namespace="/" extends="struts-default"> <action name="testingAction" class="com.mkyong.common.action.TestingAction" > <interceptor-ref name="timer"/> <interceptor-ref name="logger"/> <result name="success">pages/result.jsp</result> </action> </package>
In above snippet code, it map the “
timer” and “
logger” interceptors to the “
TestingAction” action class via “
interceptor-ref” element.
The interceptors will fire in the order they’re declared.
Since the “
TestingAction” is declared it’s own interceptors, it’s immediate loses all the inherit default set of interceptors, you must explicitly declare the “
defaultStack” in order to use it, see below example.
<package name="default" namespace="/" extends="struts-default"> <action name="testingAction" class="com.mkyong.common.action.TestingAction" > <interceptor-ref name="timer"/> <interceptor-ref name="logger"/> <interceptor-ref name="defaultStack"/> <result name="success">pages/result.jsp</result> </action> </package>
相关文章推荐
- JQuery+Strusts1.x无刷新登录
- Flex Namespace的用法
- ajax使用不同namespace的action的方法
- java struts常见错误以及原因分析
- Struts之logic标签库详解
- thinkphp autoload 命名空间自定义 namespace
- PHP命名空间(namespace)的使用基础及示例
- C++ namespace相关语法实例分析
- PHP命名空间(Namespace)简明教程
- PHP命名空间(Namespace)的使用详解
- JavaScript创建命名空间(namespace)的最简实现
- struts2的select标签用法实例分析
- SSH框架网上商城项目第20战之在线支付平台
- java中struts 框架的实现
- sprng和struts有什么区别?
- ASP.Net中命名空间Namespace浅析和使用例子
- SpringMVC+MyBatis项目总结(三)
- MyEclipse7.5+JDK1.6+Tomcat6+Struts1.3+MySQL4.1开发演示
- struts使用拦截器注解
- 懒到极致:对mybatis的进一步精简