In Struts 2, can the name attribute of action be a path? By that I mean can it be the following:
<action name="/api/method/call" ...>
Is there any source that has explained what attributes the action tag in Struts config can have. Struts seem to be really undocumented.
You can see docs on this section Action Names. However, it is not the same like yours, because of the leading slash.
Action Names With Slashes
If your action names have slashes in them (for example,
<action name="admin/home" class="tutorial.Admin"/>
) you need to specifically allow slashes in your action names via a constant in thestruts.xml
file by specifying
<constant name = "struts.enable.SlashesInActionNames" value = "true"/>
. See JIRA Issue WW-1383 for discussion as there are side effects to setting this property totrue
.
You can remove the leading slash and see if it's working or use a convention plugin with Action Annotation.
Action Annotation
The Convention plugin allows action classes to change the URL that they are mapped to using the
@Action
annotation. This annotation can also be used inside the@Actions
annotation to allow multiple URLs to map to a single action class. This annotation must be defined on action methods like this:public class HelloWorld extends ActionSupport { @Action("/different/url") public String execute() { return SUCCESS; } }
Our action class will now map to the URL
/different/url
rather than/hello-world
. If no@Result
(see next section) is specified, then the namespace of the action will be used as the path to the result, on our last example it would be/WEB-INF/content/different/url.jsp
.