STRUTS2 Interceptor Summary

Source: Internet
Author: User

The nature of the Interceptor:

An interceptor is a class, a class that implements the interceptor of a super interface. The Interceptor interface defines three methods of Init (), Destory (), intercept (). where Inercept () is the core method, the parameter of the method is invocation, and its type is the Actioninvocatio interface, which defines the core method of interception invoke ();

The interceptor-oriented aspect programming (AOP), which inserts the necessary ancillary services before or after the execution of the target code, reduces the coupling of the system. The target code of the Struts2 Interceptor is action.

Steps to use interceptors:

1. First create a class that implements the Interceptor interface. This class is the core code of the Interceptor execution, which executes before and after the target object.

Note that interceptor is a super interface and it implements three methods. Alternatively you can inherit the Abstractinterceptor abstract class, just implement the Interceptor () method on the line. Alternatively, you can inherit the Methodfilterinterceptor abstract class, just implement the Dointercept () method.

2. ( important ) Configure the Interceptor in the Struts.xml package: first declare the Interceptor, then put the custom interceptor into the interceptor stack.

Error-prone when configuring interceptors, collect the following data references:

Http://www.blogjava.net/zzzlyr/archive/2009/10/12/297998.html

Order of execution of interceptors:

The interceptor stack is called the Order of implementation, if an interceptor stack has a,b,c three interceptors, then their order of execution is a,b,c,action,c,b,a.

  

    

STRUTS2 Interceptor Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.