, 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.