Dynamic method call 1, Struts2 default turn off DMI feature, need to use manual open, configure constant
[HTML]View PlainCopy
- Struts.enable.DynamicMethodInvocation = true
2, use "!" method, which is the action name! The method name.
Struts.xml
[HTML]View PlainCopy
- <action name="Query" class="action. Queryaction ">
- <result name="Success">/success.jsp</result>
- <result name="Update">/update.jsp</result>
- </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
- Struts.enable.DynamicMethodInvocation = true
2. Wording
Struts.xml
[HTML]View PlainCopy
- <action name="*_*" class= "action.{ 1}action " method=" {2} ">
- <result>{1}_{2}succ.jsp</result>
- </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