Wildcards in struts2

Source: Internet
Author: User

, Configure the Action wildcard (wildcard)

Use wildcards to minimize the configuration quantity. However, you must abide by the principle that "conventions are better than configurations ".

1. wildcard characters

Asterisk (*) indicates all

{Number} indicates the number of wildcards

For example: Student *, then {1} represents the first asterisk (*)

* _ * {1} indicates the first asterisk (*), and {2} indicates the second asterisk (*)


[Html]
<Package name = "actions" extends = "struts-default" namespace = "/actions">
<Action name = "Student *" class = "com. bjsxt. struts2.action. StudentAction" method = "{1}">
<Result>/Student {1} _ success. jsp </result>
</Action>

<Action name = "* _ *" class = "com. bjsxt. struts2.action. {1} Action" method = "{2}">
<Result>/{1 }_{ 2} _ success. jsp </result>
<! -- {0} _ success. jsp -->
</Action>
</Package>

<Package name = "actions" extends = "struts-default" namespace = "/actions">
<Action name = "Student *" class = "com. bjsxt. struts2.action. StudentAction" method = "{1}">
<Result>/Student {1} _ success. jsp </result>
</Action>

<Action name = "* _ *" class = "com. bjsxt. struts2.action. {1} Action" method = "{2}">
<Result>/{1 }_{ 2} _ success. jsp </result>
<! -- {0} _ success. jsp -->
</Action>
</Package>

Explanation: the name of the first Action is name = "Student *" method = "{1}", indicating that all actions starting with Student will execute this Action, the method with the name after Student is executed. For example, if the accessed Action is Studentadd, this Action (Student *) is executed and the add method is executed. because {1} represents add here, And the/Studentadd_success.jsp page is returned.

Name of the second Action = "* _ *" method = "{2}" class = "... Action. {1} Action "indicates that all actions that contain underscores (" _ ") will execute this Action. For example: Teacher_add, the Action will be executed and the corresponding class of the Action is TeacherAction, and execute the add method in Action. The returned result page is/Teacher_add_success.jsp, because here {1} indicates Teacher, {2} indicates add

1. Matching order

When there are more than two matched actions, the Action will be followed by the Action with the higher matching accuracy. When there is the same matching accuracy, the Action will be performed in sequence.


 

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.