gpt4 book ai didi

java - 在 Struts 2 中, Action 的名称属性可以是路径吗?

转载 作者:行者123 更新时间:2023-11-30 08:35:12 25 4
gpt4 key购买 nike

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

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

是否有任何来源解释了 Struts 配置中的 action 标签可以具有哪些属性。 Struts 似乎真的没有文档记录。

最佳答案

您可以在这部分查看文档 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.


关于java - 在 Struts 2 中, Action 的名称属性可以是路径吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38385935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com