Friday 5 December 2014

Interceptors


Interceptors are just like filters in servlets. As you observe the below figure, a request is processed through the interceptor, before it handled by action object.


How to declare interceptors
<interceptors>
            <interceptor name="validation" class="ValidateData"/>
            <interceptor name="logger" class="LogData"/>
</interceptors>

You can declare interceptors inside a package like above.

How to apply interceptor to action
 <action name="numberCheck" class="NumberCheckAction">
            <interceptor-ref name="validation" />
            <result name="success">/success.jsp</result>
            <result name="failure">/failure.jsp</result>
</action>

Use <interceptor-ref> element to apply an interceptor to an action. In the above case interceptor ‘validation’ is applied to the action named ‘numberCheck’.



As you observe the above figure, whenever client submits a request, it passes through interceptors before action class handles it. In the same way, result also passed back to the client, through interceptors in reverse order.


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment