We are developing an Struts 2 base web application.
Please let me know which is correct (standard) in Strust 2 application
<s:url var="url" action="foo" namespace="bar" />
<s:url var="url" action="/foo" namespace="/bar" />
<s:url var="url" action="foo" namespace="/bar" />
Long story:
To get an action url we always used below
<s:url var="url" action="foo" namespace="bar" />
We tried to add the rest support to our application and make our application support rest and non rest actions same as mentioned in REST and non-RESTful URL's Together Configuration
and also Struts2 REST and Non-REST action together.
It seems that the <s:url var="url" action="foo" namespace="bar" /> is always mapped to default action, while the <s:url var="url" action="/foo" namespace="/bar" /> works fine.
Is it a bug in org.apache.struts2.dispatcher.mapper.PrefixBasedActionMapper class or the action and namespace should always have slashes?
Below the line
says that you should use Convention plugin, that means convention based action mapper. This mapper allows the action name with a leading slash. You are using Struts for years and should know that default action mapper doesn't.
The
s:urltag doesn't define any namespace or action in the configuration, it's usingUrlHelperto generate url based on its own logic. What is generated is used to access the action mapper. Normally URLs are generated withIf you print the url generated from the tags you'll see which is correct one. We are using namespace with a leading slash and action name without slash in the action attribute. These values should correspond to the configuration settings.