The following small series will share with you an article on the Struts2 configuration package default Action learning notes. If you are interested, please refer
When a front-end request is sent to the struts framework, if the request sent at this time is not configured in strtus. xml, the following error occurs:
HTTP Status 404-There is no Action mapped for namespace/and action name dasddion.
1. For example, our front-end request is:
LoginAction
2. The content of our struts configuration file is as follows:
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"> <Default-action-ref name = "myAction"/> <Action name = "myAction" class = "org. Rudiment. action. LoginAction"> <Result name = "input">/login. jsp </result> <Result name = "error">/error. jsp </result> <Result name = "success">/welcom. jsp </result> </Action> </Package> </Struts>
|
3. Description:
Strtus. only one action name = "myAction" is configured in xml. struts finds the default action to process the request because there is no matching action in the current request, as shown in the preceding figure, <default-action-ref name = "myAction"/> the default action is myAction, that is, when the corresponding action cannot be found based on the request under this package, the Action named myAction will be used to process the business requirements, if <default-action-ref name = "myAction"/> is not configured, an error is displayed at the beginning of the document.