对Action是先于拦截器还是后于拦截器学习笔记!
From
经过老师的测试… 在各个拦截器上加断点…
可知:
Action 是在访问的时候执行。
并且先Action创建,再执行params拦截器。
所以结论是:
Action要先于params拦截器。而拦截器params在default-stacks的位置:
<interceptor-stack name="defaultStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="i18n"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="chain"/>
<interceptor-ref name="scopedModelDriven"/>
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="checkbox"/>
<interceptor-ref name="multiselect"/>
<interceptor-ref name="staticParams"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params">
<param name="excludeParams">^action:.*,^method:.*</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-ref name="debugging"/>
<interceptor-ref name="deprecation"/>
</interceptor-stack>
所以结论:
Action要先于params拦截器。
但是有些老师说,Action要先于拦截器先加载….
所以,我现在只知道是先于params,到底是所有default拦截器还不可得知!如果有更详细的,请分享给我,谢谢!
补充:
现在我明白了,Action和拦截器的顺序。我是在做struts上传的时候再知道的,如果需要看我上传的文章。可以去看看(下附链接),记得是看我struts2.xml配置的参数。
http://blog.youkuaiyun.com/pengdongneng/article/details/50977705
拦截器是在每一次请求Action的时候起作用。即对每一个struts.xml中action的每一次请求,都会先创建Action,再进行默认的defaultstack。因此,
Action先于拦截器,不仅仅是params拦截器。
总结:
- 服务器启动,先拦截器创建-》初始化init
- 访问时,Action创建
- 再进入拦截器中intercept方法
- 后Action中的方法,如:execute,getter()