[Switch] There struts2 the abnormality is no Action mapped for namespace / and action name

Call to action name of the page should be placed inside the namespace name (folder path)

     <Package Penalty for name = "Example" namespace = "/ Example" the extends = "Struts-default">
         <action name = "the HelloWorld" class = "Example .HelloWorld ">
             <the Result> /example/HelloWorld.jsp </ the Result>
         </ action>
HelloWorld.jsp file should be placed namespace =" / example "example folder which otherwise would be wrong to call action.

About namespace: 

Struts. xml file in the role of the namespace attribute under the package elements 
           
, said in front of the words: 
namespace role is to control the url address action at the appropriate package, url address is the basis of this foundation in web programming in our program different functions in fact. url address to access the corresponding triggered, this must firmly grasp, a bit like the java classpath 


text: http://www.blogjava.net/Unmi/archive/2008/05/26/203014.html 
Struts of Struts2. xml is divided package configuration package may be provided namespace attribute, such as

<package namespace = "/ secure"  ....>
     ...... 
</ Package Penalty for> 

If you do not specify the namespace attribute, the default namespace is "." Using namespace planning can facilitate access rules are applied according to different purposes. For example, under different namespace configured with different interceptors can be achieved control authority, such as under the "/ secure" Logged-in users can access, under the "/ public" publicly accessible. 

The reaction namespace is arranged directly on the access URL, such namespace = "/ secure" name = "test" the Action 

<Package namespace = "/ Secure" ....> 
       <Action name = "Test" .... 
< / package> 

to access its URL is  HTTP: // ip: Port / context / Secure / test.action , that if there is no test action in the namespace "/ secure" What happens then? Struts will try the default namespace, that is looking for test "" under. 

As another example, URL is  http: // ip: port / context / some / path / test.action  when, if no test action under the "/ some / path" namespace, is to "" 

The label <s: url value = "/ secure / test.action" /> /context/secure/test.action corresponding page file is a 

slightly Ma is <s: form action = "/ secure / test.action" .... corresponding source file is <form action = "/ context / secure / test.action" ...

but backstage with a warning: 

wARNING: No configuration found for the specified action : '/secure/test.action' namespace in: ''. Form action defaulting to 'action' attribute's literal value. 

Struts2 property value when the action Action name a whole, but this does not affect the use, this URL just to the (package namespace) + (action name ) close the shoot. 

But using a dynamic method invocation (struts.enable.DynamicMethodInvocation = true) not so lucky. It is easy to take it for granted 

<s: form action = "! / Secure / test update.action" .... generated HTML source file is action = "/ TestStruts2 / om /  test"

while backstage warning message is: 

'Action' attribute's literal value Warning: No configuration found for the specified action  :: '/ secure / test' in namespace 'Form action defaulting to.'.

When it is clear that for this action = "/ TestStruts2 / om / test", submitted It is going to get HTTP Status 404 - / context / secure / test error. 

The correct usage is <s: action ...> also has a namespace attribute, yes, that 

<s: form namespace = "/ secure" action = "! Test login"> generated HTML source file is: <form action = "/TestStruts2/om/test!login.action" ....> 

What we want is this. 

If you do not configure the namespace attribute, we can also spend it when accessing the directory hierarchy action? Yes, it is customary practice in struts1, configure <action name = "secure / test " ....> name in the slash, slash but needs to be set in Struts2 in Action Name in 

struts.enable. 

SlashesInActionNames = true default is false but Struts2 probably not agree with this approach, even behind the namespace role. 

For the above uses the frame obliquely Action Name, <s: form in use wording 

<s: form action = "secure / test"> generate the HTML source file: <form Action = "/ context / Secure / test.action" ..... 

<S: Action form = "! Secure / Test Update"> generating HTML source file: <form action = "! /  context / secure / test login.action" .....


above after adding .action without action does not matter, just to ensure that <s: form> action attribute must be and the <action> is the name matching struts.xml, if unrequited love you added to the front slash, written as 

<s: form action = "! / secure / test update">, <s: form action = "/ secure / test"> or <s: form action = "/ secure / test update.action!"> HTML source file is generated became: <form action = "/ context / secure / test" .. ... 

this is also brought from Struts1 shortcomings because Struts1 the <html: form> action attribute corresponds to the <action> the path, and the Struts2 <s: form> action attribute corresponds to the <action> The name; name to be exact match, path may add some level.

Why do I spend so some effort to make it clear that it, that is, since the use of <s: form action = ""> is sometimes OK, sometimes not, it seems very confusing, it was suspected to be an application server in the way. Frankly, the log is written Benpian complete contents above the red line yet to know meritorious, which bears out exactly meaning to write down. Because in the process you are trying to get a better understanding of others, we can not tell if their own, others can only be a foggy

Reproduced in: https: //my.oschina.net/u/2260184/blog/540572

Guess you like

Origin blog.csdn.net/weixin_34008784/article/details/92186232