Struts 2 params interceptor example

The params interceptor otherwise called parameters interceptor is utilized to set all parameters on the valuestack.

It is found in the default stack bydefault. So you don't have to determine it explicitely.

Internal working of params interceptor

It gets all parameters by calling the getParameters() strategy for ActionContext and sets it on the valuestack by calling the setValue() technique for ValueStack.

Parameters of params interceptor

There are 4 parameters characterized for params interceptor.

orderedIt is genuine bydefault however can be utilized to top-down the property setter behaviour.
paramNameMaxLengthspecifies the most extreme length for the parameter. The default length is 100 characters bydefault. The parameters length more that 100 will be ignored.
excludeParams determines the unallowed parameter names. You can determine numerous names isolated with comma.
acceptParamNames determines the acknowledged parameter names.

Example of params interceptor

Let's see the basic case of params interceptor.

  1. <action name="login" class="com.javacodegeeks.Login">  
  2.     <interceptor-ref name="params"/>  
  3.     <result name="success">login-success.jsp</result>  
  4. </action>  

Note: If you determine any interceptor for the activity explicitely, default interceptors won't be accessible for the activity class.

Struts 2 defaultStack interceptors

The params interceptor is found in the default stack. You don't need to specify interceptors found in the default-stack. The defaultStack interceptors are as follows:

  1. <interceptor-stack name="defaultStack">  
  2.                <interceptor-ref name="exception"/>  
  3.                <interceptor-ref name="alias"/>  
  4.                <interceptor-ref name="servletConfig"/>  
  5.                <interceptor-ref name="prepare"/>  
  6.                <interceptor-ref name="i18n"/>  
  7.                <interceptor-ref name="chain"/>  
  8.                <interceptor-ref name="debugging"/>  
  9.                <interceptor-ref name="profiling"/>  
  10.                <interceptor-ref name="scopedModelDriven"/>  
  11.                <interceptor-ref name="modelDriven"/>  
  12.                <interceptor-ref name="fileUpload"/>  
  13.                <interceptor-ref name="checkbox"/>  
  14.                <interceptor-ref name="staticParams"/>  
  15.                <interceptor-ref name="actionMappingParams"/>  
  16.                <interceptor-ref name="params">  
  17.                  <param name="excludeParams">dojo\..*,^struts\..*</param>  
  18.                </interceptor-ref>  
  19.                <interceptor-ref name="conversionError"/>  
  20.                <interceptor-ref name="validation">  
  21.                    <param name="excludeMethods">input,back,cancel,browse</param>  
  22.                </interceptor-ref>  
  23.                <interceptor-ref name="workflow">  
  24.                    <param name="excludeMethods">input,back,cancel,browse</param>  
  25.                </interceptor-ref>  
  26.            </interceptor-stack>  

javacodegeeks is optimized for learning.© javacodegeeks .
All Right Reserved and you agree to have read and accepted our term and condition