Struts 2 Interceptors Examples by R4R Team

Struts 2 Custom Interceptor Example

In apache struts 2 framework there are two categories of the interceptors default and custom. The default interceptors need not to be create its provided by the struts 2 , we can create the custom interceptor by implementing the Interceptor interface in a class and overriding its three life cycle method as the following given in the given example .

For creating the custom interceptor, Interceptor interface must be implemented. It has three methods:

  1. public void init() It is invoked only once and used to initialize the interceptor.
  2. public void intercept(ActionInvocation ai) It is invoked at each request, it is used to define the request processing logic. If it returns string, result page will be invoked, if it returns invoke() method of ActionInvocation interface, next interceptor or action will be invoked.
  3. public void destroy() It is invoked only once and used to destroy the interceptor.
Leave a Comment:
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!