This article will introduce Struts2 requests to match multiple wildcard instances. I hope this tutorial will be helpful to you.
When our request matches multiple actions of strtus
1. For example, the request is:
LoginAction
2. The following is our struts configuration file:
| The Code is as follows: |
Copy code |
<? Xml version = "1.0" encoding = "UTF-8"?>
<! DOCTYPE struts PUBLIC "-// Apache Software Foundation // DTD Struts Configuration 2.1 // EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<Struts>
<Constant name = "struts. custom. i18n. resource" value = "mess"/>
<Constant name = "struts. i18n. encoding" value = "GBK"/>
<Package name = "default" extends = "struts-default">
<Action name = "loginAction" class = "org. Rudiment. action. LoginAction1">
<Result name = "input">/login. jsp </result>
<Result name = "error">/error. jsp </result>
<Result name = "success">/welcom. jsp </result>
</Action>
<Action name = "* inAction" class = "org. Rudiment. action. LoginAction2">
<Result name = "input">/login. jsp </result>
<Result name = "error">/error. jsp </result>
<Result name = "success">/welcom. jsp </result>
</Action>
<Action name = "*" class = "org. Rudiment. action. LoginAction3">
<Result name = "input">/login. jsp </result>
<Result name = "error">/error. jsp </result>
<Result name = "success">/welcom. jsp </result>
</Action>
</Package>
</Struts> |
3. matching analysis:
When the same action as the request is configured, struts will directly match this action. For example, in this example, strtus will match action name = "loginAction". If no identical action is configured, strtus uses this Action to process the query match from top to bottom, for example, if action name = "loginAction" is not configured, strtus will match action name = "* inAction" for action name = "* inAction" and action name = "*" because it is not the request is exactly the same, who configured struts to handle the business, so this is handled by action name = "* inAction. If we configure action name = "*" before action name = "* inAction", strtus submits the business processing to the action name =, instead of processing the action corresponding to "* inAction.