This warning error always appears on the console when I recently learned about struts2.
My clientsCodeAs follows (Code 1 ):
<S: Form Action = "/admin/login" method = "Post"> <br/> <s: textfield name = "username" id = "usenrame" label = "username"/> <br/> <s: password name = "password" id = "password" label = "password"/> <br/> <s: submit type = "input" value = "login" id = "btnsubmit" cssclass = "btnsubmit"> </S: Submit> <br/> </S: Form>
The configuration code in struts. XML is as follows (Code 2 ):
<Package name = "admin" namespace = "/admin" extends = "struts-Default"> <br/> <action name = "login" class = "com. longweir. struts2.action. loginaction "> <br/> <result name =" success ">/actionresult. JSP </result> <br/> <result name = "login" type = "Redirect">/admin/login. JSP </result> <br/> <result name = "input">/admin/login. JSP </result> <br/> </Action> <br/> </package>
After searching on the internet, almost all the answers provided by the search network are described as <s: FormAction= "/Admin/login method =" Post "> Add login.Action suffixThe problem is still unsolved after testing.
I have observed that there are two points to be modified. First, the namespace parameter must be added to the <s: Form> form, which is consistent with the configuration in struts. xml. Second, the name of the Action ing is directly written in <s: Form Action = xxx>. For example, if my XML file is login, you can directly write Login here,You do not need to add the. Action suffix or other prepath.So the modified client file configuration is code (3 ):
<S: Form Action = "login" method = "Post" namespace = "/admin"> <br/> <s: textfield name = "username" id = "usenrame" label = "username"/> <br/> <s: password name = "password" id = "password" label = "password"/> <br/> <s: submit type = "input" value = "login" id = "btnsubmit" cssclass = "btnsubmit"> </S: Submit> <br/> </S: Form>
Of course, if you are not using the struts2 tag but using the traditional HTML code, the form action attribute must be added with the complete path and suffix, that is, the following code must be changed:
<Form name = "form" method = "Post" Action = "/admin/login. Action">
After you specify the above, when the browser gives the above request/admin/login. action, The struts2 framework will first be in sturts. search for the/admin namespace in XML. If the/admin namespace is found (for example, this namespace is obviously available here), run login. action. If no action is found, it will be searched in the default namespace. If no action is found by default, an error will be prompted and the action is not mapped.
Note:
This article Reprinted from: http://www.javaeye.com/topic/575148