struts2 配置文件 重定向 redirect (带参数) 的写法

本文介绍了Struts框架中两种重定向配置方法:使用Dispatch形式和完全Action路径形式。详细解释了URL参数间的正确连接方式,并提供了具体示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

对于所有重定向写法中URL的各参数间需要以&连接,而不能以&连接!

否则报如下错误:

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

【第一种写法】:使用Dispatch形式

[html]  view plain copy print ?
  1. <action name="*tAction" class="tAction" method="{1}">  
  2. <result name="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 plain copy print ?
  1. <action name="enterpreinfo" class="preinfoBusinessAction"    method="enterPreinfoSub">  
  2.   <result name="success" type="redirect-action">  
  3.      showpreinfo?preinfo.order_number=${preinfo.order_number}&amp;preinfo.company_name=${preinfo.company_name}  
  4.   </result>  
  5.  <result name="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}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值