gpt4 book ai didi

java - struts2 转义命名空间定义

转载 作者:行者123 更新时间:2023-12-02 00:14:05 25 4
gpt4 key购买 nike

在我的 struts.xml 中(包名称是 website),我包含了一个子 xml:

<include file="child.xml"/>

我的 struts.xml 中还有一个欢迎操作:

<action name="welcome">
<result>welcome.jsp</result>
</action>

我的child.xml扩展了struts.xml:

<package name="child" namespace="/child" extends="website">

接下来我想做的是在 child.xml 中创建一个重定向到 welcome 操作的操作。到目前为止,我的 child.xml 中有以下内容,但它不起作用:

<action name="">
<result type="redirectAction">welcome</result>
</action>

我认为它不起作用的原因是因为默认情况下它会转到 URL /child/welcome 而不仅仅是 /welcome。因此,如果可能的话,我需要一种方法来在 child.xml 的 action 定义中转义它。

最佳答案

RedirectAction 结果可以有 2 个由 Struts2 定义的特定参数。其中之一是actionName,另一个是namespace。因此,如果您想将包内部重定向到 namespace 之外的操作,则必须将以下内容放入 child.xml 中:

<action name="whatever">
<result type="redirectAction">
<param name="actionName">welcome</param>
<param name="namespace">/</param>
</result>
</action>

您可以查看与结果类型redirectAction相关的所有文档 here 。您在页面底部有一个完整的示例,说明如何重定向到不同的命名空间。

关于java - struts2 转义命名空间定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12217369/

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