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.

Reference

  1. Struts 2 interceptor documentation
  2. Struts 2 workflow interceptor documentation

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
4 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
4 Comment authors
mithun kumar PothalBinh Thanh NguyennityanandaAlfredo O Recent comment authors
newest oldest most voted
mithun kumar Pothal
Guest
mithun kumar Pothal

Helo Sir,

I want to share session in between two war files in struts2 application . is it possible ? if so could you please guide me the process

Binh Thanh Nguyen
Guest
Binh Thanh Nguyen

Thanks, nice explanation.

nityananda
Guest
nityananda

nice………..

Alfredo O
Guest
Alfredo O

Thank you, just what I needed.