1. 程式人生 > >struts2 配置檔案 重定向 redirect (帶引數) 的寫法

struts2 配置檔案 重定向 redirect (帶引數) 的寫法

對於所有重定向寫法中URL的各引數間需要以&連線,而不能以&連線!

否則報如下錯誤:

The reference to entity "arg2" must end with the ';' delimiter.

【第一種寫法】:使用Dispatch形式

[html] view plaincopyprint?
  1. <actionname="*tAction"class="tAction"method="{1}">
  2. <resultname="test"type="redirect">testtAction.action?arg1
    =${arg1}&amp;arg2=${arg2}</result>
  3. </action>

注意:

當使用DispatchAction時(在action標籤中的name使用了萬用字元*匹配方法名),此時type=“redirect”而不能寫成type=“redirect-action”。

此時在重定向的配置中,需要寫完全連線,即XXAction.action?...而不能寫成XXAction?...

【第二種寫法】:使用完全Action路徑形式:

[html] view plaincopyprint?
  1. <actionname="enterpreinfo"
    class="preinfoBusinessAction"method="enterPreinfoSub">
  2.   <resultname="success"type="redirect-action">
  3.      showpreinfo?preinfo.order_number=${preinfo.order_number}&amp;preinfo.company_name=${preinfo.company_name}  
  4.   </result>
  5.  <resultname="error"type="redirect">
  6.     <param
    name="location">/error.jsp</param>
  7.  </result>
  8. </action>

注意:

因為使用了redirect-action,所以要注意不能將showpreinf?preinfo.order_number=${preinfo.order_number}寫成showpreinf.action?preinfo.order_number=${preinfo.order_number}