【问题标题】:Forward the request to non struts 2 action from struts2 action?将请求从 struts2 动作转发到非 struts 2 动作?
【发布时间】:2013-03-01 08:49:49
【问题描述】:

我有遗留应用程序,它使用专有框架,或多或少类似于 struts 1.2。现在我们已经开始 使用 struts 2. 在很多地方,我将 html 表单提交给来自 jsp 的旧操作。我想要的是第一个请求 到我的新 struts 2 动作,然后我将请求从那里转发到我的旧动作,以便我在目标旧动作中获取所有源请求参数。我知道有结果类型 重定向(如下所述),但这不会将源请求参数转发到遗留操作。

@Result(name = "displayCustomer",
        location = "legacyAction.do", type = "redirect")


@Action("display-customer!displayCustomer")
  public String displayCustomer() {
    return "displayCustomer";
  }

我没有找到任何类似于重定向的“转发”类型。我不确定如何将请求转发到来自 struts 2 的非 struts 2 动作 行动?

【问题讨论】:

  • 默认响应类型是转发。为什么要先行动?
  • 因此,如果我想将这些遗留动作转换为 struts 2 动作,我没有修改 jsps/view。
  • 你说默认响应类型是转发,这是否意味着我不必在结果注释中提及 type = "redirect"。在这种情况下,所有请求参数都将转发到我的旧操作。是吗?
  • @Dave 我试着只给@Result(name = "displayCustomer", location = "legacyAction.do") 将请求转发给旧版操作,但服务器没有启动?
  • 响应没有任何东西可以阻止重定向到动作,无论它是否是旧的,大多数调整都是为了使其与不在值堆栈上的对象兼容。可以选择将旧版操作与旧版插件链接起来吗?

标签: java model-view-controller struts2


【解决方案1】:

您可以根据结果类型(例如SUCCESS)简单地将控件转发到相应页面。您可以使用chain结果类型一次执行两个不同的操作。

看起来像这样:

使用 XML 配置

    <action class="your_action_path" name="your_action_name" method="your_target_method">
                <result type="chain">your_legacy_action</result>
    </action>

     //Then your_legacy_action_mapping here

<action class="your_legacy_action_path" name="your_legacy_action_name" method="your_target_method">
                <result>your_target_success_page</result>
    </action>

【讨论】:

  • 我认为动作转换是将请求从 struts 2 动作转发到另一个 struts 2 动作而不是传统动作。我认为为了将请求转发给遗留操作,我们只是 nedd disptcher
【解决方案2】:

在struts2 中默认结果类型被配置为'dispatcher'。它“转发”请求。 尝试设置 type="dispatcher"。检查您的 struts 配置是否正确配置了“调度程序”结果类型。它应该如下所示。

<result-types>
   <result-type name="dispatcher" default="true"
                class="org.apache.struts2.dispatcher.ServletDispatcherResult" />
</result-types>

【讨论】:

  • 我正在使用注释。应该是@Result(name = "displayCustomer", location = "legacyAction.do", type="dispatcher") 吗?
  • 是的。检查您的 struts 配置 (struts.xml) 以确保您已如上所示注册了结果类型。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
  • 2022-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-21
相关资源
最近更新 更多