我正在尝试从 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 访问主包中的操作
最佳答案
这两个问题都可以通过在主包中的每个操作中设置 "/"
命名空间来解决:
@Namespace("/")
当请求url为
/anything/limit.action
而 Struts 无法找到该 Action ,它将在默认的 ""
命名空间中寻找 LimitAction。
关于java - 将 Struts 2.3 迁移到 2.5 时遇到的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39568189/