有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将请求从struts2 action转发到非struts2 action?

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

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


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

我没有发现任何类似于重定向的“转发”类型。我不知道如何从struts 2将请求转发给非struts 2操作 行动


共 (2) 个答案

  1. # 1 楼答案

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

    它将如下所示:

    使用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>
    
  2. # 2 楼答案

    在struts2中,默认结果类型配置为“dispatcher”。“转发”请求。 尝试设置type=“dispatcher”。检查struts配置是否正确配置了“dispatcher”结果类型。它应该看起来像下面的东西

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