2016-09-28 57 views
-1

我有一個應用程序,我想在struts.xml中用新條目修改(或覆蓋)動作映射。 這裏有詳細的解釋。如何動態更改struts.xml中的動作類條目?

在我的申請中,我有不同的階段,如註冊,change_data,我使用context Param管理這些階段。

的web.xml

<context-param> 
    <description>Current stage of the application</description> 
    <param-name>stage</param-name> 
    <param-value>registration</param-value> 
</context-param> 

我有一個動作是重定向支付網關即支付網關請求被髮送到用戶這一行動。

struts2.xml(示範項目)

<!-- for registration --> 
<action name="paymentResponse" class="abc.xyz.PaymentResponse"> 
    <result name="input" type="tiles">paymentForReg.tiles</result> 
    <result name="success" type="tiles">home.tiles</result> 
</action> 

<!-- for change data --> 
<action name="paymentResponse" class="abc.xyz.PaymentResponseForChangeData"> 
    <result name="input" type="tiles">paymentForChangeData.tiles</result> 
    <result name="success" type="tiles">home.tiles</result> 
</action> 

所以當應用變化的階段,我在做什麼是web.xml變化階段和評論從struts.xml

所以從動作的一個條目總結我有多個具有相同名稱的動作,我想根據context param觸發(或更改動作類名稱)動作。有沒有辦法做到這一點?

+0

https://struts.apache.org/docs/wildcard-mappings.html –

+0

通配符將不起作用,因爲我想更改'action class','action Name'必須相同。鑑於基於'actionName'的通配符工作 – piechuckerr

+0

由於在Struts2中操作類是隱藏的,並且操作名稱是公開的,而且這是需要的,那麼您的需求會聞到很多XY問題 –

回答

0

如果我沒有錯,我認爲你必須使用類似下面的動態動作,那麼你可以使用XML

struts.xml中相同的動作和相同的條目:

<action name="paymentResponse" class="abc.xyz.RedirectPaymentResponse" method="updateCriteria"> 
     <result name="response" type="tiles">paymentForChangeData.tiles</result> 
     <result name="responsechanged" type="tiles">paymentForReg.tiles</result> 
     <result name="success" type="tiles">home.tiles</result> 
</action> 

Action類:

public class RedirectPaymentResponse extends AbstractAppAction { 


     public String execute() throws Exception 
     { 
      // some code 
      return "success"; 
     } 

     public String updateCriteria(){ 

      //logic here 

      if(PaymentResponse){ 
      // code here 
      return "response"; 

      } 

      if(PaymentResponseChanged){ 
      // code here 
      return "responsechanged" 

      } 

}