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">
            <interceptor-stack name="crudStack">
              <interceptor-ref name="checkbox" />
                <interceptor-ref name="params" />
                <interceptor-ref name="staticParams" />
                <interceptor-ref name="defaultStack" />


make own interceptor stack

    <interceptor name="sessioninterceptor"
         <interceptor-stack name="sessionStack">
                 <interceptor-ref name="params" />
                 <interceptor-ref name="sessioninterceptor"></interceptor-ref> 

and use it.

<action name="Abc"
            <interceptor-ref name="sessionStack"/>

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

Popular posts from this blog

What is NBioBSP Java Library?

Draw arrow line example

Capture image from webcam java code, examples