Home Struts Struts Struts2.2.1 Introduction to Interceptor 

Ask Questions?

View Latest Questions


 
 

Introduction to Interceptor 
Posted on: January 29, 2011 at 12:00 AM
Advertisement
Interceptors are one of the most powerful features of struts2.2.1. the introduction of interceptors into struts2.2.1 framework

Introduction to Interceptor 

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".

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-

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.

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.

 

Related Tags for Introduction to Interceptor :


DMCA.com