gpt4 book ai didi

java - 命名空间(和操作)应该以斜杠开头吗?

转载 作者:行者123 更新时间:2023-11-30 06:39:40 30 4
gpt4 key购买 nike

我们正在开发一个基于 Struts 2 的 Web 应用程序。

请告诉我 Strust 2 应用程序中哪个是正确的(标准)

<s:url var="url" action="foo" namespace="bar" />
<s:url var="url" action="/foo" namespace="/bar" />
<s:url var="url" action="foo" namespace="/bar" />

长话短说:

要获取我们在下面始终使用的操作网址

<s:url var="url" action="foo" namespace="bar" />

我们尝试向我们的应用程序添加休息支持,并使我们的应用程序支持休息和非休息操作,如 REST and non-RESTful URL's Together Configuration 中提到的那样。

还有Struts2 REST and Non-REST action together .

看来 <s:url var="url" action="foo" namespace="bar" />始终映射到默认操作,而 <s:url var="url" action="/foo" namespace="/bar" />工作正常。

这是 org.apache.struts2.dispatcher.mapper.PrefixBasedActionMapper 中的错误吗?类或操作和命名空间应该始终带有斜杠?

最佳答案

线下

REST and non-RESTful URL's Together Configuration

And, again, we're relying on the Convention plugin to find ourcontrollers, so we need to configure the convention plugin a bit:

<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package" value="rest-default"/>
<constant name="struts.convention.package.locators" value="example"/>

表示您应该使用约定插件,这意味着基于约定的 Action 映射器。此映射器允许操作名称带有前导斜杠。您使用 Struts 多年,应该知道默认操作映射器不会。

s:url 标签在配置中没有定义任何命名空间或操作,它使用 UrlHelper 根据自己的逻辑生成 url。生成的内容用于访问操作映射器。通常 URL 是用

生成的
 http://<host>:<port>/<context>/<namespace>/<action>[.<extension>]

如果您打印从标签生成的网址,您将看到哪个是正确的。我们使用带有前导斜杠的命名空间和在操作属性中不带斜杠的操作名称。这些值应与配置设置相对应。

关于java - 命名空间(和操作)应该以斜杠开头吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44601892/

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