Can view the tutorials best in Google Chrome, Mozilla Firefox, Opera, higher version of Internet Explorer

Struts2 Custom Interceptor Example, Struts2 Interceptors

Struts » On Apr 4, 2012 | { 4 Comments }

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
  • LogingEx.java
  • MyInterceptor.java

Directory Structure

index.jsp

success.jsp

LogingEx.java

MyInterceptor.java

web.xml

struts.xml

Output

Note:
In MyInterceptor.java, 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.

 

 

What you are thinkig....

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.

    Thanks
    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.

    Regard,
    Narottam Singh

If you want a pic to show with your comment, go get a gravatar !
Please post your questions on Java4s Answers forum

Name*
Ask a Question ?
or
Mail*
Website



By posting your answer, you agree to our comments policy.
Most Recent Tutorials
Hibernate Recent Posts
Spring Recent Posts
Struts Recent Posts
Recomandded Links Current & UpComing Tutorials Java4s.com
Tutorials Online :
spring Hibernate struts Json Ajax Log4j Log4j
coreJava Servlets


UpComing :
Jsps,Web Services
Java4s is optimized for learning java technologies, all the examples in this site are constantly reviewed to avoid errors. While using this site you agree to have read and accepted our terms of use and privacy policy
Especially i have prepared this blog by keeping fresher's in mind, however it will be very useful for real time developers too.


© 2014 Java4s All rights reserved. | strPro4Tut v(2.0) Theme designed by Team Java4s.