Summary of struts2 interceptor implementation

Source: Internet
Author: User

1. inherit the AbstractInterceptor class or implement the interceptor interface. Because AbstractInterceptor is the implementation class of interceptor, the general methods in the interface are implemented, but they are used to inherit AbstractInterceptor. Just like the Action in struts2 inherits ActionSupport and does not implement the Action interface. 2. It is more feasible to inherit the AbstractInterceptor class. Invocation. invoke (); indicates that the execute () method of the Action is executed after the method is executed, or the next interceptor invocation is executed. getAction (); this method can be forcibly converted to the class type of Action. 3. Method Interceptor: inherits the MethodFilterInterceptor class and overwrites doIntercept () method MethodFilerInterceptor two parameters used in method filtering execludeMethods: this parameter specifies the list of methods that the interceptor rejects. Multiple methods are separated by commas (,) and this parameter is specified, the interceptor does not intercept methods in the specified list, that is, the so-called blacklist includeMethods: this parameter specifies the list of methods to intercept by the Interceptor. If a parameter is specified, the specified Action will be intercepted before execution, whitelist. After the custom interceptor is defined, you must use the custom interceptor in struts. in xml document 1, define interceptor 1 <package...> 2 <interceptors> 3 <interceptor name = "myinterceptor" class = ".... "> 4 </interceptor> 5 </interceptors> 6 </package> 2. Use interceptor 1 in action <action ......> 2 <result...> </result> 3 <interceptor-ref name = "defaultStack"> </interceptor-ref> 4 <interceptor-ref name = "myinterceptor"> </interceptor-ref> 5 </action> mainly: we can see that the reference of the default interceptor should be configured for the action of the custom interceptor, because the default interceptor contains the reading of parameters, session management, and other functions.

Related Article

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.