簡體   English   中英

將請求從struts2動作轉發到非struts 2動作?

[英]Forward the request to non struts 2 action from struts2 action?

我有一個使用專有框架的遺留應用,該專有框架或多或少類似於struts 1.2。現在我們已經開始使用struts2。在很多地方,我正在將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動作?

您可以根據結果類型(例如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>

在struts2中,默認結果類型配置為'dispatcher'。 哪個“轉發”請求。 嘗試設置type =“ dispatcher”。 檢查您的struts配置是否正確配置了“ dispatcher”結果類型。 它應該看起來像下面的東西。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM