Remove the namespace from the package element.
The page for calling the action name should be placed in the namespace name (folder, PATH)
<Package name = "example" namespace = "/example" extends = "struts-Default">
<Action name = "helloworld" class = "example. helloworld">
<Result>/example/helloworld. jsp </result>
</Action>
The helloworld. jsp file should be placed in the namespace = "/example" example folder. Otherwise, an error occurs when calling the action.
About namespace:
Role of the namespace attribute under the package element in the Struts. xml file
As mentioned above:
The role of namespace is to control the URL address of the action under the corresponding package. The URL address is the basis of WEB programming. the different functions of our program are actually triggered by access to the corresponding URL address. This should be well grasped, a bit like the Java classpath.
Original article: http://www.blogjava.net/Unmi/archive/2008/05/26/203014.html
Struts. xml of struts2 is configured by package. You can set the namespace attribute for the package, as shown in figure
<Package namespace = "/secure"...>
......
</Package>
If the namespace attribute is not specified, the default namespace is "". Using namespace allows you to easily plan access rules for applications for different purposes. For example, different interceptors can be configured in different namespaces to control permissions. For example, if you have logged on to a user under "/secure", you can access them publicly under "/public.
The configured namespace is directly reflected in the access URL, for example, namespace = "/secure" name = "test" Action
<Package namespace = "/secure"...>
<Action name = "test "....
</Package>
The URL for accessing it is http: // ip: Port/Context/secure/test. Action. What happens if no test action is found in namespace "/secure? Struts will also try to find test under the default namespace, that is.
For another example, the URL is http: // ip: Port/Context/Some/path/test. if test action cannot be found under "/Some/path" namespace, test action is also found under "(default namespace, but not under "/some.
Use the tag <s: URL value = "/secure/test. Action"/>. The corresponding page source file is/Context/secure/test. Action.
<S: Form Action = "/secure/test. action ".... the corresponding source file is <form action = "/Context/secure/test. action "...
However, there is a warning in the background:
Warning: No configuration found for the specified action: '/secure/test. action' in namespace:'. Form Action defaulting to 'action' attribute's literal value.
Struts2 treats the attribute value of action as the whole action name, but this does not affect usage. This URL can be closed with (package namespace) + (action name.
However, it is not so lucky to use dynamic method call (struts. Enable. dynamicmethodinvocation = true. It is easy to take for granted
<S: Form Action = "/secure/test! The HTML source file generated by update. Action "... is action ="/teststruts2/OM/test"
At the same time, the background warning information is:
Warning: No configuration found for the specified action: '/secure/test' in namespace:'. Form Action defaulting to 'action' attribute's literal value.
Obviously, when this action = "/teststruts2/OM/test" is submitted, the HTTP status 404-/Context/secure/test error is returned.
The correct usage is that <s: Action...> also has a namespace attribute.
<S: Form namespace = "/secure" Action = "test! Login "> the generated HTML source file is: <form action ="/teststruts2/OM/test! Login. Action "...>
This is what we want.
If the namespace attribute is not configured, can we use the directory hierarchy when accessing the action? Yes, that is the practice in struts1. Configure <action name = "Secure/test"...> name to use a slash, but in struts2 to use a slash in action name.
Struts. Enable. slashesinactionnames = true default value: false
However, struts2 probably does not agree with this practice, so it is quite helpful for namespace.
For the action name in the oblique box used above, the statement in <s: Form should be used
<S: Form Action = "Secure/test"> Generate the HTML source file: <form action = "/Context/secure/test. Action ".....
<S: Form Action = "Secure/test! Update "> Generate HTML source file: <form action ="/Context/secure/test! Login. Action ".....
The preceding action is not added. action doesn't matter, but make sure that the action attribute of <s: Form> must be consistent with struts. in XML, if you add a slash in front of the <action> name, as shown in
<S: Form Action = "/secure/test! Update ">, <s: Form Action ="/secure/test ">, or <s: Form Action ="/secure/test! Update. Action "> the generated HTML source files are all: <form action ="/Context/secure/test ".....
This is also caused by struts1, because the <HTML: Form> action attribute in struts1 corresponds to the path of <action>, and in struts2 <s: the action attribute of form> corresponds to the name and name of <action>. You can add layers to the path.
Note Transfer
When running a simple struts2 helloworld program, the there is no action mapped for namespace/and action name helloworld error occurs, but the configuration is basically ruled out.
I found a lot of Methods online, finally solved, is to put the Struts. xml file in the WEB-INF/classes directory, the previous habit of using struts1 is under the WEB-INF directory, leading to errors.
- HTTP statushttp status 404-no result defined for action and result Input
This is because the data submitted by the form has an error and the conversion is abnormal, so the action has an error and will be switched to the input configuration. If the input result is not configured, this error will be reported.
In addition, when a method error occurs, other methods of this action also report an error. The action was originally handed over to spring for hosting, And the instance is no longer a singleton, therefore, other methods requested by the instance after an error are the same, so the instance is always in an error state.
Configure bean to scope = "prototype" in the spring configuration file. The problem is solved.