Infolinks In Text Ads

Sep 25, 2010

Interceptor in struts2 java

Interceptor Definition:-
           
         In struts2, An Interceptor is an interface under the com.opensymphony.xwork2.interceptor package. An Interceptor extends the Serializable Interface. An interceptor is a stateless class that follows the interceptor pattern.
    Interceptor give the choice to write code that can be invoke before and after the execution of an action. Interceptor also have the facility to stop an action from executing. Interceptors provide developers a way to encapulate common functionality in a re-usable form that can be applied to one or more Actions.


How to use of Interceptor:-

 <package name="default" extends="struts-default">
        <interceptors>
            <interceptor-stack name="crudStack">
              <interceptor-ref name="checkbox" />
                <interceptor-ref name="params" />
                <interceptor-ref name="staticParams" />
                <interceptor-ref name="defaultStack" />
            </interceptor-stack>
        </interceptors>
    </package>

or

make own interceptor stack

<interceptors>
    <interceptor name="sessioninterceptor"
             class="com.SessionInterceptor"/>
         <interceptor-stack name="sessionStack">
                 <interceptor-ref name="params" />
                 <interceptor-ref name="sessioninterceptor"></interceptor-ref> 
         </interceptor-stack>   
    </interceptors>

and use it.

<action name="Abc"
            class="com.ActiveAction"
            method="getList">
           
            <interceptor-ref name="sessionStack"/>

            <result name="error">/jsp/login/login.jsp</result>
            <result>
                /jsp/active.jsp
            </result>
        </action>

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...