Home Struts Struts Struts2.2.1 Interceptor orders Configuration in Struts application

Ask Questions?

View Latest Questions


 
 

Interceptor orders Configuration in Struts application
Posted on: January 29, 2011 at 12:00 AM
Advertisement
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. -

<interceptor-stack name="MyStack">

                   <interceptor-ref name="First"/>

                   <interceptor-ref name="Second"/>

                    <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.

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

<struts>

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

                        <interceptors>

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

                                  <interceptor-stack name="loggerStack">

                                                              <interceptor-ref name="logger" />

                                                             <interceptor-ref name="defaultStack" />

                                   </interceptor-stack>

                         </interceptors>

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

                               <interceptor-ref name="loggerStack" />

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

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

        </action>

    </package>

</struts>

The See the Example go to the link-

Interceptor Example

Related Tags for Interceptor orders Configuration in Struts application:


DMCA.com