In Struts 2 Action的name属性可以是路径吗?

In Struts 2 Can Name Attribute of Action Be a Path?

在Struts 2、action的name属性可以是路径吗?我的意思是它可以是以下内容吗:

<action name="/api/method/call" ...>

是否有任何来源解释了 Struts 配置中的操作标签可以具有哪些属性。 Struts好像真的没有证件。

文档 link 供您参考。

https://struts.apache.org/docs/home.html

您可以在操作名称中使用斜线,但不建议这样做,

您可以查看此部分的文档 Action Names。但是,由于前导斜杠,它与您的不一样。

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 the struts.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 to true.


您可以删除前导斜杠并查看它是否正常工作或使用带有 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.