Interceptor orders Configuration in Struts application
Posted on: January 29, 2011 at 12:00 AM
The Struts2.2.1 Framework uses the concept of interceptors to share the solutions for some common concern by different action.

Interceptor orders Configuration in Struts application

The Struts2.2.1 Framework uses the concept of  interceptors to share the solutions for some common concern by different action. Some Action performing validation of inputs, some need to pre-processing of file to be upload, other Actions may be performing other tasks like display action on page. The Framework invokes makes it easy by using the Interceptors.When a request is initialize,The framework invokes a particular Action object on the Submission of a request for it, and before the execution of Action, the invocation is intercepted by another object to provide additional processing capability. Similarly, After the Action executes, the invocation could be intercepted again by the interceptor. these interceptor objects ia called as "Interceptors".

The Interceptors (defined in the stack) execution order are specifies according to the stack. The Interceptor are executed according to the order defined in the Interceptor-Stack, The default Interceptor-Stack have all the Interceptor and in the predifined order. but we can change the Execution order by making custom Interceptor-Stack.  In some cases, the order of the Interceptors execution on the stack can be very important.The given action mapping can create an "ad-hoc" interceptor stack.

The General Syntax for the Order Configuration of Interceptor is as. -ADS_TO_REPLACE_1

<interceptor-stack name="MyStack">

                   <interceptor-ref name="First"/>

                   <interceptor-ref name="Second"/>ADS_TO_REPLACE_2

                    <interceptor-ref name="Third"/>

                    <interceptor-ref name="Fourth"/>

</interceptor-stack>

 In the given Syntax the order of the Interceptor execution is according to the order of <interceptor-ref> tags within the <interceptor-stack> tag.ADS_TO_REPLACE_3

The struts.xml file of the Interceptor example is as follows-

<struts>

     <package name="roseindia" extends="struts-default">ADS_TO_REPLACE_4

                        <interceptors>

                                   <interceptor name="logger" class="roseindia.InterceptorAction"> </interceptor>

                                  <interceptor-stack name="loggerStack">ADS_TO_REPLACE_5

                                                              <interceptor-ref name="logger" />

                                                             <interceptor-ref name="defaultStack" />

                                   </interceptor-stack>ADS_TO_REPLACE_6

                         </interceptors>

        <action name="Interceptor" class="roseindia.InterceptorAction">

                               <interceptor-ref name="loggerStack" />ADS_TO_REPLACE_7

                                           <result name="success">/Interceptor.jsp</result>

                                           <result name="error">/index.jsp</result>

        </action>ADS_TO_REPLACE_8

    </package>

</struts>

The See the Example go to the link-

Interceptor Example ADS_TO_REPLACE_9

Related Tags for Interceptor orders Configuration in Struts application:

Advertisements

Ads

Ads

 
Advertisement null

Ads