2

我正在尝试从 Struts 2.3 迁移到 2.5.2,但我有两个奇怪的问题。它们在 2.3 中很好,所以问题可能出在 Convention 插件上。

假设我有两个动作:

mypackage.actions.LimitAction
mypackage.actions.user.UserAction

在 2.3 中:

http://myurl/limit.action          -> OK
http://myurl/anything/limit.action -> There is no Action ... which is OK
http://myurl/user/user.action      -> OK

在 2.5 中:

http://myurl/anything/limit.action -> OK ... which should be There is no Action ...

如果我在 struts.xml 中设置默认操作:

<default-action-ref name="other" />

<action name="other" class="mypackage.actions.OtherAction">
    <result />
</action>

然后

http://myurl/limit.action          -> went wrong and OtherAction is shown

似乎如果我有默认操作,那么主包(mypackage.actions)中的每个操作都被 OtherAction 隐藏,但是

http://myurl/anything/limit.action -> still works which is wrong too

它是 Struts 2.5.2 中的错误吗?如何在不使主包中的操作出错的情况下设置默认操作?如何修复不使用 anyurl/*.action 访问主包中的操作

4

1 回答 1

1

"/"通过在主包中的每个操作中设置命名空间来解决这两个问题:

@Namespace("/")

当请求 url 是

/anything/limit.action 

并且 Struts 找不到动作,它会在默认""命名空间中查找 LimitAction。

于 2016-09-19T09:51:30.430 回答