In this tutorial you will learn about the Struts 2 Interceptors and its application with practical example.
Struts2 Interceptors
The task which are executed by the Struts2 framework before and after an Action is executed are done by Interceptors. These are standard Java Classes which are included in the Struts2 core jar. Interceptors are responsible for the request processing. Interceptors are mostly used in Validation, Exception Handling, internationalization etc.
Default Interceptors
Some of mostly used Struts2 Default Interceptors are listed below, have a look on that.
alias: This interceptor is used to convert similar parameter that have different names between request.
checkbox: This interceptor is used to detect unchecked checkboxes in the form.
cookie: This interceptor is used to adding a cookie in current action.
conversionError: This interceptor is used to add conversation error to the action’s field errors.
createSesssion: This interceptor is used to creates HttpSession if there is no session available.
clearSession: This interceptor is used to clear the existing session.
validation: This interceptor is used to provides validation support for actions.
token: This interceptor checks the action for a valid token to prevent duplicate form submission.
i18n: This interceptor provides the support of internationalization and localization.
exception: This is used for mapping exception to a result.
fileUpload: This interceptor is used for file uploading in Struts2 .
timer: This interceptor used to provides time of the action takes to execute.
ServletConfig: This interceptors provides the action with access to servlet-based information.
scope: This interceptor is used to store the action state in the session or application scope.
debugging: This interceptor is used for debugging.
params: This interceptor is used to sets the request parameters on the action.
perpare: This is typically used to do pre-processing work like setup database connection.