Interceptors are one of the most powerful features of struts2.2.1. the
introduction of interceptors into struts2.2.1 framework is set it apart from
other frameworks. An interceptor, as the name implies, intercepts the request
and provides some additional processing before and after the execution of
action and result. An interceptor is a stateless class that follows the interceptor pattern, as
found in Filter
and in AOP languages.
Definition:- "Interceptors are objects that dynamically intercept Action invocations. They provide the developer with the opportunity to define code that can be executed before and/or after the execution of an action".
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".ADS_TO_REPLACE_1
Interceptors must be stateless and not assume that a new instance will
be created for each request or Action. The Interceptors (defined in the stack) execution order are specifies according to the 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 Action Life Cycle-
ADS_TO_REPLACE_2
The Working of the Innterceptor is clearly shown by the figure as follows-
1- The ServletDispatcher initializes The ActionProxy to call the execute() method, and the request is Intercepted by the Interceptor before action is executed.
2- The request is Intercepted by the Interceptor before and/or after the action is executed and completed.ADS_TO_REPLACE_3
3- After the execution of the action is performed then the request is sent to the Result page to render the result and show to the user.
Advertisements
Ads
Ads