Configuring Interceptors in struts.xml 
Posted on: January 29, 2011 at 12:00 AM
The Interceptors to be used in the web application is declared in the struts.xml file.

Configuring  Interceptors in strut.xml 

The Interceptors to be used in the web application is declared in the struts.xml file. The Interceptor class can be defined using a name-class pair in the Struts configuration file(struts-default.xml). If you extend the struts-default package, then you can use the names given in struts-default.xml. Otherwise, they must be defined in your package with a name-class pair specified in the <interceptors> tag.We can also use another .xml file for configuring the Interceptors by including that file in the struts.xml file.

The Configuration of Interceptors in the struts.xml file is as follows:-

<package name="default" extends="struts-default">
    <interceptors>
       <interceptor name="timer" class="roseindia.MyJSP"/>
       <interceptor name="logger" class="roseindia.MyJSP"/>
    </interceptors>

    <action name="myJSP" class="roseindia.MyJSP">
         <interceptor-ref name="timer"/>
         <interceptor-ref name="logger"/>
             <result name="input">MyJSP.jsp</result>
             <result name="success" type="redirectAction">/jsp/home.jsp</result>
    </action>
</package>

Interceptor stack-

In most of the web applications, The same set of interceptors used multiple times, so rather than repetition of same set of  Interceptors, we can use collectively these interceptors using Interceptor Stack. ADS_TO_REPLACE_1

<package name="default" extends="struts-default">
   <interceptors>
        <interceptor name="timer" "roseindia.MyJSP"/>
       <interceptor name="logger" class="roseindia.MyJSP"/>
        <interceptor-stack name="myStack">
           <interceptor-ref name="timer"/>
          <interceptor-ref name="logger"/>
        </interceptor-stack>
    </interceptors>

   <action name="myJSP" class="roseindia.MyJSP">
         <interceptor-ref name="myStack"/>
            <result name="input">MyJSP.jsp</result>
            <result name="success" type="redirectAction">/jsp/home.jsp</result>
   </action>
</package>

The Following Example helps you in understanding the Configuration of Interceptors.

Interceptor Example

Related Tags for Configuring Interceptors in struts.xml :

Advertisements

Ads

 
Advertisement null

Ads