In Struts 2 I am seeing the root namespace giving the same behaviour as the root namespace, ie acting as a "catch all". I need to restrict actions in my app to be accessible from only one URL, including those without a namespace in the URL. My understanding is using root namespace should do this but I haven't seen it work.
I can reproduce this problem with the Struts 2 tutorial's HelloWorld example for Eclipse available here.
The struts.xml contains
<package name="basicstruts2" extends="struts-default">
...
<action name="index">
<result>/index.jsp</result>
</action>
...
</package>
So both the following links show the index.jsp result
- localhost:8080/Basic_Struts2_Ant/index.action
- localhost:8080/Basic_Struts2_Ant/foo/index.action
Good so far.
If I change the struts.xml to
<package name="basicstruts2" namespace="/foo" extends="struts-default">
- localhost:8080/Basic_Struts2_Ant/index.action fails with "There is no Action mapped for namespace / and action name index."
- localhost:8080/Basic_Struts2_Ant/foo/index.action shows index.jsp
Also good.
Now if I change struts xml to say
<package name="basicstruts2" namespace="/" extends="struts-default">
Both the following links show the index.jsp result (same as when no namespace is defined)
- localhost:8080/Basic_Struts2_Ant/index.action
- localhost:8080/Basic_Struts2_Ant/foo/index.action
If I have understood the namespace documentation correctly I would expect localhost:8080/Basic_Struts2_Ant/foo/index.action to fail with "There is no Action mapped for namespace /foo and action name index."
I have also tried other variants, replacing "foo" with "alksdja" etc, to eliminate browser caching as a possibility.
Have I misunderstood what the root namespace does? And how to disable /foo/index.action from working while allowing /index.action?