Javatpoint Logo

91-9990449935

 0120-4256464

Struts 2 Interceptors Tutorial

Interceptor is an object that is invoked at the preprocessing and postprocessing of a request. In Struts 2, interceptor is used to perform operations such as validation, exception handling, internationalization, displaying intermediate result etc.

Advantage of interceptors

Pluggable If we need to remove any concern such as validation, exception handling, logging etc. from the application, we don't need to redeploy the application. We only need to remove the entry from the struts.xml file.


Struts 2 default interceptors

There are many interceptors provided by struts 2 framework. We have option to create our own interceptors. The struts 2 default interceptors are as follows:

1) alias It converts similar parameters that have different names between requests.

2) autowiring

3) chain If it is used with chain result type, it makes the properties of previous action available in the current action.

4) checkbox It is used to handle the check boxes in the form. By this, we can detect the unchecked checkboxes.

5) cookie It adds a cookie to the current action.

6) conversionError It adds conversion errors to the action's field errors.

7) createSession It creates and HttpSession object if it doesn't exists.

8) clearSession It unbinds the HttpSession object.

9) debugging It provides support of debugging.

10) externalRef

11) execAndWait It sends an intermediate waiting page for the result.

12) exception It maps exception to a result.

13) fileUpload It provides support to file upload in struts 2.

14) i18n It provides support to internationalization and localization.

15) jsonValidation It provides support to asynchronous validation.

16) logger It outputs the action name.

17) store It stores and retrieves action messages, action errors or field errors for action that implements ValidationAware interface.

18) modelDriven It makes other model object as the default object of valuestack.

19) scopedModelDriven It is similar to ModelDriven but works for action that implements ScopedModelDriven.

20) params It populates the action properties with the request parameters.

21) actionMappingParams

22) prepare It performs preparation logic if action implements Preparable interface.

23) profiling It supports action profiling.

24) roles It supports role-based action.

25) scope It is used to store the action state in the session or application scope.

26) servletConfig It provides access to maps representing HttpServletRequest and HttpServletResponse.

27) sessionAutowiring

28) staticParams It maps static properties to action properties.

29) timer It outputs the time needed to execute an action.

30) token It prevents duplication submission of request.

31) tokenSession It prevents duplication submission of request.

32) validation It provides support to input validation.

33) workflow It calls the validate method of action class if action class implements Validateable interface.

34) annotationWorkflow

35) multiselect