Reduce the number of actions in struts2 (used by wildcards)

Source: Internet
Author: User
For example, Struts has the following actions, and manageruseraction has the corresponding method.

< Action Name = "Adduser" Class = "Com. netshuai. Action. manageruseraction" Method = "Add" >
< Result Name = "Success" > /Adduser. jsp </ Result >
</ Action >
< Action Name = "Deluser" Class = "Com. netshuai. Action. manageruseraction" Method = "Del" >
< Result Name = "Success" > /Deluser. jsp </ Result >
</ Action >
< Action Name = "Updateuser" Class = "Com. netshuai. Action. manageruseraction" Method = "Update" >
< Result Name = "Success" > /Updateuser. jsp </ Result >
</ Action >

If you use wildcards, You can omit them as an action.

< Action Name = "* User" Class = "Com. netshuai. Action. manageruseraction" Method = "{1 }" >
< Result Name = "Success" > /{1} user. jsp </ Result >
</ Action >

* Is a wildcard and {1} is replaced by *. For example, the user accesses adduser. * is automatically replaced with ADD, and {1} is also replaced with ADD.

If Uniform Naming rules are used during development, all actions can be replaced with one similar to the following. < Action Name = "*_*" Class = "Com. netshuai. Action. {1} action" Method = "{2 }" >
< Result Name = "Success" > /{2} _ {1} success. jsp </ Result >
</ Action >

As shown above, all files adopt Uniform Naming rules. The first * is the classification name, and the second * is the operation name, {1} and {2} represent the replacement values of the first and second * respectively. All Action Implementation classes are named classification names + actions.
For example, if the category name is user and the operation name is add, the accessed action name is user_add.action, the implementation class name is useraction, And the return Page name is add_usersuccess.jsp.
In addition, {0} indicates that all Wildcards are displayed, as shown in figure < Result Name = "Success" > /{2} _ {1} success. jsp </ Result > Change < Result Name = "Success" > /{0} success. jsp </ Result >, The returned name is user_addsuccess.jsp.

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.