Method filter of struts2 interceptor

Source: Internet
Author: User

The struts2 framework provides the methodinterceptor class. A custom interceptor can use the method filtering function of the Interceptor to intercept specific methods in the action as long as the class is integrated.

(You can view the methodinterceptor documentation. I did not check the declaration here. A subclass of COM. opensymphony. xwork2.interceptor. abstractinterceptor Interceptor to implement interceptor and serializable interfaces .) Two important parameters: 1. excludemethods: this parameter specifies the list of methods that the interceptor rejects. If there are multiple method values, use the commas (,) to encode them, for example, "Method1, method2 ". If this parameter is specified, the interceptor does not intercept the specified action method, similar to the so-called blacklist. 2. includemethods: this parameter specifies the list of methods to be intercepted by the Interceptor. If there are multiple method values, use commas to separate them. If this parameter is specified, the specified action will be intercepted by the interceptor before execution, that is, the so-called whitelist. Note: If the same action method is specified for the blacklist and whitelist, this method will not be blocked. The main method of the methodinterceptor class: protected abstract string dointercept (actioninvocation Invocation): The subclass that inherits this class must override this method and implement the interceptor logic. (If the methodinterceptor class is not inherited, the intercept () method is forcibly rewritten instead of the dointercept () method ); String intercept (actioninvocation Invocation): inherits the SUBCOM. opensymphony. xwork2.interceptor. abstractinterceptor class. This method does not need to be forcibly rewritten. Void setexcludemethods (string includemethods): sets the whitelist of the Interceptor. This method parameter is a string, that is, the corresponding action method name. After this method is set, the interceptor intercepts this method. Set getexcludemethodsset (): gets the blacklist of the interceptor. Set getincludemethodsset (): gets the whitelist of the interceptor. If you use a subclass of the methodfilterinterceptor class to filter the methods of the interceptor, you do not need to rewrite the intercept (actioninvocation Invocation) method as previously. Here you only need to override the dointercept (actioninvocation Invocation) method. Note: There is no difference between the method filter interceptor and the common interceptor, But it inherits Com. opensymphony. xwork2.interceptor. Subclass of abstractinterceptor class methoidfilterinterceptor, and rewrite Dointercept (actioninvocation Invocation) method; Sample configuration file for Implementing Method filter interception:
<Action name = "filteraction" class = "filteractionclass"> <result name = "success">/success. JSP </result> <result name = "input">/error. JSP </result> <Interceptor-ref name = "defaultstack"> </interceptor> <Interceptor-ref name = "filterinterceptor"> <! -- Use method filtering to set the whitelist or blacklist --> <Param name = "excludemethods"> Method1 </param> <! -- Do not intercept Method1 in action --> <Param name = "includemethods"> method2 </param> <! -- Intercept method2 in action --> </Action>

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.