java - 将 Struts 2.3 迁移到 2.5 时遇到的问题

标签 java http configuration struts2 struts-action

我正在尝试从 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/

相关文章:

java - 这可以只用递归来完成吗?

c# - 如何查看HTTPRequest信息

java - 正确实现 HttpCacheStorage?

visual-studio-2010 - Visual Studio:在项目或解决方案设置上设置默认项目

java - 如何从命令行读取值并在引导注释配置类中使用它们来定义spring bean?

java - Spring bean通过方法初始化

java - 如果您使用单独的配置文件,则无法使用 Firefox geckodriver,它会给出错误 : java. lang.OutOfMemoryError:Java 堆空间

java - 如何将自定义 Spring Data Neo4j 5.0.3 密码查询标记为只读

java - 无法解析 org.springframework.security.core.GrantedAuthority,即使它已下载/显示在项目库下

ios - 提供对在通过 iOS 个人热点连接的笔记本电脑上运行的开发 Web 服务器的访问