struts2事先在struts-default.xml中定义了许多拦截器和适合不同用途的拦截器栈
下面是struts2提供的一些自带拦截器栈
<interceptors>
<!--省略了拦截器定义-->
<!-- Basic stack -->
<interceptor-stack name="basicStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="checkbox"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params"/>
<interceptor-ref name="conversionError"/>
</interceptor-stack>
<!-- Sample validation and workflow stack -->
<interceptor-stack name="validationWorkflowStack">
<interceptor-ref name="basicStack"/>
<interceptor-ref name="validation"/>
<interceptor-ref name="workflow"/>
</interceptor-stack>
<!-- Sample JSON validation stack -->
<interceptor-stack name="jsonValidationWorkflowStack">
<interceptor-ref name="basicStack"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel</param>
</interceptor-ref>
<interceptor-ref name="jsonValidation"/>
<interceptor-ref name="workflow"/>
</interceptor-stack>
<!-- Sample file upload stack -->
<interceptor-stack name="fileUploadStack">
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="basicStack"/>
</interceptor-stack>
<!-- Sample model-driven stack -->
<interceptor-stack name="modelDrivenStack">
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="basicStack"/>
</interceptor-stack>
<!-- Sample action chaining stack -->
<interceptor-stack name="chainStack">
<interceptor-ref name="chain"/>
<interceptor-ref name="basicStack"/>
</interceptor-stack>
<!-- Sample i18n stack -->
<interceptor-stack name="i18nStack">
<interceptor-ref name="i18n"/>
<interceptor-ref name="basicStack"/>
</interceptor-stack>
<interceptor-stack name="paramsPrepareParamsStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="i18n"/>
<interceptor-ref name="params"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="chain"/>
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="checkbox"/>
<interceptor-ref name="staticParams"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params"/>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel</param>
</interceptor-ref>
</interceptor-stack>
<!-- A complete stack with all the common interceptors in place.
Generally, this stack should be the one you use, though it
may do more than you need. Also, the ordering can be
switched around (ex: if you wish to have your servlet-related
objects applied before prepare() is called, you'd need to move
servlet-config interceptor up.
This stack also excludes from the normal validation and workflow
the method names input, back, and cancel. These typically are
associated with requests that should not be validated.
-->
<interceptor-stack name="defaultStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="i18n"/>
<interceptor-ref name="chain"/>
<interceptor-ref name="debugging"/>
<interceptor-ref name="profiling"/>
<interceptor-ref name="scopedModelDriven"/>
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="checkbox"/>
<interceptor-ref name="staticParams"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*</param>
</interceptor-ref>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
</interceptor-stack>
<!-- The completeStack is here for backwards compatibility for
applications that still refer to the defaultStack by the
old name -->
<interceptor-stack name="completeStack">
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
<!-- Sample execute and wait stack.
Note: execAndWait should always be the *last* interceptor. -->
<interceptor-stack name="executeAndWaitStack">
<interceptor-ref name="execAndWait">
<param name="excludeMethods">input,back,cancel</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="execAndWait">
<param name="excludeMethods">input,back,cancel</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
struts-default包默认的拦截器栈为defaultStack,因为其他自定义的包全继承自该包,所以我们自己定义的package的默认拦截器栈都为defaultStack。可以在package中添加一下语句指定默认的拦截器栈
<default-interceptor-ref name="myStack"/>
注意:如果我们要使用自己定义的栈,struts2会只使用我们定义的拦截器而不会执行框架默认的拦截器。所以自定义拦截器栈时一定要记得将系统的默认栈加进去,如下所示
<package name="default" extends="struts-default">
<interceptors>
<interceptor name="timer" class=".."/>
<interceptor name="logger" class=".."/>
<interceptor-stack name="myStack">
<interceptor-ref name="timer"/>
<interceptor-ref name="logger"/>
<!--记住一定要加上下面这句-->
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<action name="login"class="tutuorial.Login">
<interceptor-ref name="myStack"/>
<result>success.jsp</result>
</action>
</package>
注意:定义拦截器栈时要注意拦截器的顺序,因为某些拦截器会中断stack/chain/flow
分享到:
相关推荐
Struts2拦截器(Interceptor) Struts2拦截器(Interceptor)
Struts2拦截器.ppt Struts2拦截器.ppt Struts2拦截器.ppt
struts2,Interceptor struts2拦截器实例,两套实例,一套是针对单个的action配置的,另一套实例是针对全局的action配置的拦截器interceptor
关于struts2 拦截器的详细的解释及其在开发中对struts2的拦截器的应用和拦截器在框架中的作用.
Struts2拦截器实现权限控制demo,我感觉对初学者还是有一定帮助的
基于struts2的拦截器测试,实现了页面的跳转,中间过程的拦截
struts2拦截器的使用说明文档,配置说明文档。可以看一下
struts2拦截器应用小例子,与大家共分享
NULL 博文链接:https://cmexico.iteye.com/blog/621208
Struts2拦截器源程序 Struts2拦截器源程序 Struts2拦截器源程序 Struts2拦截器源程序 Struts2拦截器源程序
NULL 博文链接:https://lipeixiaoyu.iteye.com/blog/626707
Struts2拦截器原理分析实例 博文链接:https://zmx.iteye.com/blog/457432
struts2拦截器和验证框架
NULL 博文链接:https://pihai.iteye.com/blog/352287