Home Struts Struts2.3.15.1 Creating own Interceptor
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Creating own Interceptor

Advertisement
Though Interceptors are provided by default in the stack, one can also create custom interceptors and add it to already existing list of interceptors. It is very easy to create your own interceptor. Custom made Interceptors provide cross-cutting application features.

Creating own Interceptor

Though Interceptors are provided by default in the stack, one can also create custom interceptors and add it to already existing list of interceptors. It is very easy to create your own interceptor.

Custom made Interceptors provide cross-cutting application features. Custom interceptors can be customized according to the need. Interceptors can be executed before and after an action is executed.

Following Interceptor interface needs to be extended:

public interface Interceptor extends Serializable{
void destroy();
void init();
String intercept(ActionInvocation invocation)
throws Exception;
}

Interceptor's init() method is called while initializing the interceptor

Interceptor's destroy() method is called during the destruction of interceptor

Code is placed in intercept (ActionInvocation). If init() and destroy() methods are not needed then AbstractInterceptor class can be extended.

To invoke Interceptor after an action is executed, place the code after invocation.invoke (). (invocation.invoke() is responsible for executing the next interceptor in the stack or action)

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 21, 2013

Ask Questions?    Discuss: Creating own Interceptor  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com