I meet some problem when I try to learn the namespace of struts2,I am using struts-2.2.1.
After read the docs at: http://struts.apache.org/2.2.1/docs/namespace-configuration.html I am confused for the following reason: The example: <package name="default"> <action name="foo" class="mypackage.simpleAction"> <result name="success" type="dispatcher">greeting.jsp</result> </action> <action name="bar" class="mypackage.simpleAction"> <result name="success" type="dispatcher">bar1.jsp</result> </action> </package> <package name="mypackage1" namespace="/"> <action name="moo" class="mypackage.simpleAction"> <result name="success" type="dispatcher">moo.jsp</result> </action> </package> <package name="mypackage2" namespace="/barspace"> <action name="bar" class="mypackage.simpleAction"> <result name="success" type="dispatcher">bar2.jsp</result> </action> </package> This is the explanation: *If a request is made to /barspace/foo.action, the namespace /barspace will be checked for action foo. If a local action is not found, the default namespace is checked. In the Namespace Example, there is no action foo in the namespace /barspace, therefore the default will be checked and /foo.action will be executed.* I wonder why it is '/foo.action' rather than 'foo.action",it said that it will find the foo.action at the default namespace,and the default namespace is "",so it should be foo.action,why there is a '/'?? ALso problem 2: *Namespace are not hierarchical like a file system path. There is one namespace level. For example if the URL /barspace/myspace/bar.action is requested, the framework will first look for namespace /barspace/myspace.* For the request url "/barspace/myspace/bar.action", the '/barspace/myspace' will be splitted as a namespace,so what is the action now? is it the "/bar.action" or "bar.action",since the "/" may stand for a root namespace. I am really confused,anyone can give me a detailed suggestion?? so I do some test: This is the struture of my test project: Struts_TestProject ----WebContent --------js(floder) --------jsp() ------------reg.jsp ------------thank.jsp --------WEB-INF ------------web.xml ------------lib() --------index.jsp 1)Default namespace test First I did not define the namespace in the struts.xml: <package name="test" extends="struts-default"> <action name="register" class="com.strutstest.action.RegisterAction" method="execute"> <result name="success">/jsp/thank.jsp</result> </action> </package> This is the HTML form(I am not intend to use the tag now): <form action="register" method="post"></form> It works well, the page will jump to thank.jsp,the only problem is I have not found any way to pass some parameters to the thank.jsp and render them in the page.However this is not the main problem, I think I will make it clear oneday. 2)set a namespace Then I tried to test the namespace, I add a namespace to the package: <package name="test" extends="struts-default" namespace="space"> ...Other configuration are same as it in the above. Then I call it by this manner: <form action="space/register" method="post"></form> Then the struts show me the exception: **There is no Action mapped for action name register** (The following parameter is I get from debugging step by step at the IDE :(:( String servletPath = request.getServletPath()=== /jsp/space/register String requestUri = request.getRequestURI()==== /Struts_Test/jsp/space/register Then the "/jsp/space/register" is used to parsed the namespace and action name,at last the namespace is set to "" since there is not a mached namespace named "/jsp/space".And the name is set to "register". Obviously, it is wrong. Since the brower add the "jsp" prefix in the action. ) To avoid the browser add a "jsp" prefix in the action, I tried to set the action in form like: <form action="/space/register" method="post"></form> The exception is the same as before. Then I se the namespace from "space" to "/space",I also get the same excetpion as before if I use the action to "space/register" in the HTML form,however I will get a 404 error if I set the action to "/space/register". I am crazying!!! How the hell does the namespace work ???????? BTW, how does the "result" element in the "action" location the page?That's to say ,for exmaple <result name="success">/jsp/thank.jsp</result> how to locat the thank.jsp? Is it based the base path of the web context? Is the first "/" required?