在一个Action里面单独覆盖: (http://www.mkyong.com/struts2/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.
在一个package下的所有Action都覆盖:
上面的只对一个Action进行了参数覆盖,如果我们要对我们定义的一个package下所有的Action都覆盖该怎么办呢?
<package name="my-pack" extends="struts-default"> <interceptors> <interceptor-stack name="anti-remote-command-execution"> <interceptor-ref name="defaultStack"> <param name="params.excludeParams">dojo\..*,^struts\..*,.*\\.*,.*\(.*,.*\).*,.*@.* </param> </interceptor-ref> </interceptor-stack> </interceptors> <default-interceptor-ref name="anti-remote-command-execution" /> <action name="act1" class="" /> <action name="act2" class="" /> </package>