In this example we will see how to implement Interceptors. Struts 2 Framework API provides mechanism to controlling requests using interceptors.
1. Create a struts web application
Please see previous examples to create simple Struts 2 web application
2. Create an Interceptor class (HelloNameInterceptor.java)
To create interceptors we have to implement Interceptor interface and override intercept method. Inside this method we can do the intercepting whatever needed. In this example i am adding logging before and after executing action.
3. Configuring Interceptor in Struts.xml
4. Run application
Run this application and input your name as parameter, in the console log we will see below intercepting details