Interceptors in struts 2


Interceptor is an object which is called at the pre processing and post processing of a request. These are same as the filters in the servlet.

Use of interceptors in struts 2.

  1. Interceptors are used to perform some pre-processing task before the action is invoked.
  2. Interceptors are used to perform some post-processing task after the action is invoked.
  3. Interceptors are used to perform operations like validation, internationalization etc
  4. Interceptors can also be used to catch exceptions.

Commonly used default interceptors of struts 2.

  1. alias: It allows same parameters to have different alias name across requests.
  2. checkbox: It is used to manage the check boxes by adding the false value for unchecked checkboxes.
  3. conversionError: It is used to add the conversion errors into the action’s field errors.
  4. execAndWait: It is used to send the user to an intermediate waiting page while action is executed.
  5. i18n: It is used to track the selected locale during a session. It provides the internationalization and localization facilities.
  6. debugging: It provides debugging support to the developer.
  7. exception: It provides the automatic exception handling facility by mapping the exception from an action to the result.
  8. fileUpload: It provides the facility to upload files.
  9. logger: It outputs the executed action name.
  10. validation: It provides the validation support.

Struts 2 logger interceptor example:


<%@ taglib uri="/struts-tags" prefix="s"%>
		<title>Struts 2 logger interceptor example</title>
		<h3>This is a logger interceptor example.</h3>
		<s:form action="test">
			<s:submit value="Hello" align="center"/>


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 


"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
	<package name="user" extends="struts-default">
		<action name="test" 
			<interceptor-ref name="logger"/>
			<result name="success">/welcome.jsp</result>

 * This class is used as an action class.
 * @author w3spoint
public class Test {
	//business logic
	public String execute(){
		return "success";	


<%@ taglib uri="/struts-tags" prefix="s"%>
		<title>Struts 2 logger interceptor example</title>
		<h3>This is a logger interceptor example.</h3>	 


struts 8 first   Click on Hello button. struts 8 final   Download this example.   Next Topic: Struts 2 execAndWait interceptor with example. Previous Topic: Value Stack in struts 2 with example.


Content Protection by