Struts 2 override the interceptor parameters

In Struts 2, you can set or override the interceptor parameters via the generic <param> tag. See below example

<package name="default" namespace="/" extends="struts-default">
   <action name="whateverAction" 
    class="com.mkyong.common.action.WhateverAction" >
    <interceptor-ref name="workflow">
        <param name="excludeMethods">whateverMethod</param>
    </interceptor-ref>
    <result name="success">pages/whatever.jsp</result>
   </action>        
</package>

However, in above snippet, the action class is declared it’s own interceptor, and it will cause the immediate lose of the inherit “defaultStack” interceptors.

What if you want to keep the “defaultStack” interceptors, and override the workflow’s excludeMethods parameter as well? No problem, try this

<package name="default" namespace="/" extends="struts-default">
   <action name="whateverAction" 
    class="com.mkyong.common.action.WhateverAction" >
    <interceptor-ref name="defaultStack">
        <param name="workflow.excludeMethods">whateverMethod</param>
    </interceptor-ref>
    <result name="success">pages/whatever.jsp</result>
   </action>        
</package>

The above snippet will keep the “defaultStack” interceptor and override the “workflow” parameter.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章