Struts2 Custom Interceptor Example, Struts2 Interceptors

Struts » On Apr 4, 2012 By Sivateja

Let us see how to create user defined interceptors in struts2, we already know this fact that struts2 by default provided lot of interceptors. In fact we no need to create any custom interceptors :-) , but this is the way to create custom interceptors if you would like to.

Let us see the steps to create our own interceptor

  • Create one java class which should implements from Interceptor interface, see all interceptors in struts2 must implements from Interceptor interface only
  • Override all abstract methods in Interface interface, Interceptor contains 3 abstract methods init(), destroy(), intercept(ActionInvocation inv)
  • Finally configure our interceptor class in struts.xml file that’s it, let us see the example

Struts2 Custom Interceptor Example

Required files…

  • index.jsp
  • success.jsp
  • web.xml
  • struts.xml

Directory Structure






In, line number 23 we are calling invoke() method of ActionInvocation. Actually invoke() method will take cares the total journey of executing pre-post logic for our Action class.


Java/J2EE Developer & Web Designer, founder of Sign-up for the email newsletter for your daily dose of Java tutorials.


4 Responses to “Struts2 Custom Interceptor Example, Struts2 Interceptors”
  1. Mohammed Vaseem says:

    Hello java4s,

    Please provide the concepts of ValueStack, ActionContext, OGNL as these are the fundamentals to struts2.

    Mohammed Vaseem

  2. Sri says:

    Hi java4s

    Please provide more Real time points

  3. Pooja Tekwani says:

    Hello Sir,

    I am using Struts2 Jquery Plugin, and if I click on two radio buttons alternatively than two different should be loaded… If you can guide me with my query than it’ll be really helpful to me…

    Thanks & Regards,
    Pooja Tekwani

  4. Hello, Sivateja

    I am continue reader of you post. I read all your post and everything is helpful for me and everyone . I need one example of Struts 2x with display taglib library for pagination. I used Struts 1x and it’s working fine .
    so please provide me any small example as soon as possible which will be helpful for me and another one also.

    Narottam Singh


By posting your answer, you agree to our comments policy.
© 2010 - 2016
Java4s - Get It Yourself.
The content & design is copyrighted to Sivateja Kandula, it may not be reproduced on other websites.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs

Most Recent Tutorials
Hibernate Recent Posts
Spring Recent Posts
Struts Recent Posts
Recomandded Links
Current & UpComing Tutorials
  Web Services [ SOAP ], JSP
Facebook_Java4s  Twitter_Java4s  GooglePlus_Java4s  Youtube_Java4s 
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2016 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.