Interceptors in Struts2

The Struts2 framework provides very important features known "Interceptor". It is used to controlling request and response. The Interceptor executed before and after the Action. So It can be used to process some logics on the request before Action and after Action also. It is same as Filter concept of J2EE application. Most of the framework implemented the interceptor functionality.

The Struts2 framework comes with set of pre defined interceptors and common interceptor stacks. The following features like double-submit guards, type conversion, object population, validation, file upload, page preparation, and more, are all implemented with the help of Interceptors. When a developer create package by extending "struts-default", the "defaultStack" interceptor stack is implemented automatically.

Interceptor architecture in Struts2 :

Interceptor architecture in Struts2

The following are common interceptors comes with Struts 2 bundeled :
Interceptor Name Description
alias Interceptor This Interceptor aliases different request parameters name to different Action properties
chain Interceptor This Interceptor is used to dispatch action request to other action instead of View page. It works with result type; like <result type="chain">
cookie Interceptor It is used to read certain cookies and values, You can read all cookies from the localsystem or name and valie can filter also
debugging Interceptor It is used to display several debuging screens into data binding page
execAndWait Interceptor It is used to display intermediate page while Action is executing in background
exception Interceptor If exception is occured, it maps exceptions with result
fileUpload Interceptor Automatically file upload before Action when request contains multipart/form-data
logger Interceptor This interceptor logs the start and end of the execution an action
modelDriven Interceptor It is used to create model class (POJO) other than Action and use it in Action to map request parameters
scopedModelDriven Interceptor This interceptor retrieves and stores the model object from a scope and sets it on the action calling setModel
params Interceptor Sets the request parameters onto the Action
prepare Interceptor It is used to prepare any object in Action before processing any methods
scope Interceptor Simple mechanism for storing Action state in the session or application scope
servletConfig Interceptor Provide access to Maps representing HttpServletRequest and HttpServletResponse
validation Interceptor It is used to validate data by ActionName-validation.xml file or Annotations

Let's demostrate some common interceptors :
Previous Next

Share your valuable comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code :

Comment by : Jackman August 12th, 2017
Comment : Good to learn

Comment by : sabari November 30th, 2016
Comment : nice tutorial i am understand quickly

Comment by : angel May 13th, 2016
Comment : good work

Comment by : Rajesh July 8th, 2014
Comment : Nice Explaination

Comment by : Rakesh January 17th, 2014
Comment : nice tutorial

Comment by : Rakesh January 17th, 2014
Comment : nice work, Keep it up !

Comment by : laxmi December 3rd, 2013
Comment : nice to leran

Comment by : krishanshukla November 25th, 2013
Comment : good