Struts2 Dynamic Method Invocation (DMI) and wildcard mappings

Source: Internet
Author: User

Dynamic method call 1, Struts2 default turn off DMI feature, need to use manual open, configure constant

[HTML]View PlainCopy
    1. Struts.enable.DynamicMethodInvocation = true

2, use "!" method, which is the action name! The method name.

Struts.xml

[HTML]View PlainCopy
  1. <action name="Query" class="action. Queryaction ">
  2. <result name="Success">/success.jsp</result>
  3. <result name="Update">/update.jsp</result>
  4. </Action>


The request URL is/query!success.action, calling Actio.queryaction's success () method;

Request URL is/query!update, call Actio.query's update () method;

The. Action on the path can be written or not written, and Struts2 is added by default. Action is the suffix, and if you change the suffix name, for example,. Do, the declaration is displayed.

3. Benefits: Reduce the number of actions, but the number of result sets is the same.

Wildcard mappings

1. No Configuration required

[HTML]View PlainCopy
    1. Struts.enable.DynamicMethodInvocation = true


2. Wording

Struts.xml

[HTML]View PlainCopy
    1. <action name="*_*" class= "action.{ 1}action " method=" {2} ">
    2. <result>{1}_{2}succ.jsp</result>
    3. </Action>


The request URL is/query_success, calling Actio. Success () method of queryaction;

{1}, {2} indicates the location of the wildcard character, where {1} represents query,{2} for success;

Another {0} represents the entire wildcard character, which represents query_success, so the result set above can also be written as {0}succ.jsp

3, the advantage: reduce the number of actions at the same time, reduce the number of result sets, reflect the "contract better than the configuration", while adding code, do not need to make changes to the Struts.xml file;

4. URL Request order: When more than one Action is successfully matched, such as xaction, *action, *, for request xaction, match xaction, ignore the order of Xaction, for request Yaction, by *action, * In the order of occurrence of struts.xml, the first occurrence of the first call

5. Match the path with "/":

(1) Config constant struts.enable.SlashesInActionNames = True

(2) Some writing with * * match with "/" path, but I do not need to experiment results * *, direct */* can

From: http://blog.csdn.net/abc45628/article/details/45482649

Struts2 Dynamic Method Invocation (DMI) and wildcard mappings

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.