2013-03-01 55 views
1

我有遺留應用程序正在使用專業框架或多或少像struts 1.2.Now我們已經開始 使用struts 2.在很多地方,我提交的HTML表單從jsp舊的行動。我想要的是第一個請求去 到我新的struts 2行動,然後我轉發請求到我的遺產行動從那裏,我得到所有來源請求參數在目標遺留action.I知道有結果類型 重定向(如上所述下面),但不會將源請求參數轉發給傳統操作。將請求轉發到struts2 action的非struts 2動作?

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


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

我沒有找到任何類型的「轉發」類似於重定向。我不知道如何將請求轉發到struts 2 action中的非struts 2動作?

+0

默認響應類型是正向。你爲什麼想先行動? – 2013-03-01 11:16:57

+0

因此,如果我想將這些遺留行爲轉換爲struts 2行爲,那麼我沒有修改jsps/view。 – emilly 2013-03-01 14:22:55

+0

你說默認的響應類型是向前的,這是否意味着我不必在結果註釋中提及type =「redirect」。在這種情況下,所有的請求參數將被轉發到我的傳統操作。是嗎? – emilly 2013-03-01 14:24:53

回答

1

你可以簡單地轉發控制根據您的結果類型,例如成功相應的頁面。你可以使用結果類型在同一時間執行兩個不同的操作。

它看起來是這樣的:

使用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> 
+0

我認爲行動chaning是轉發請求從struts 2行動到另一個struts 2行動而不是遺產行動。我認爲,爲了將請求轉發給傳統行動,我們只需要解散器 – emilly 2013-03-02 14:48:23

0

在struts2中默認結果類型被配置爲'dispatcher'。 「轉發」請求。 嘗試設置type =「dispatcher」。檢查你的struts配置'dispatcher'結果類型是否配置正確。它應該看起來像下面的東西。

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

我正在使用註釋。它應該是@Result(name =「displayCustomer」,location =「legacyAction.do」,type =「dispatcher」)? – emilly 2013-03-02 08:43:22

+0

是的。檢查你的struts配置(struts.xml),以確保你的註冊結果類型如上所示。 – 2013-03-03 05:25:21