struts2配置文件中参数的传递

在Action中我们经常会从这个Action跳转到另一个Action中,如果只是简单的跳转那么很容易,只需在struts配置文件中添加一个result,如:<result name="index">/manager/managerInfo/account.jsp</result>.

   result有一个type属性,这里的type默认是dispatcher,但这种情况下action之间是不能发送请求的,这时我们就要用到redirect、redirect-action、chain,当要请求一个action时,可设定type的值为以上三个中的一个
如:
<result name="reload" type="redirectAction" >/manager/managerInfo/account.action</result>.


   如果想在请求的过程中添加参数可以像超链接传值一样在最后用"xx?xx=xx"的形式来传递参数.
如:
<result name="reload" type="redirectAction">/manager/ managerInfo/account.action?参数名=参数值</result>


,如果这里的参数值不是一个固定值可以用"${参数值}"这种形式,需要注意的是这里的"参数值"在相应的Action中一定要提供get/set方法,否则将无法获得参数值,当然这里也同样可以取一个对象的某个属性值即:${对象名.属性名},
假如我想取得一个帐户的帐号:
<result name="reload" type="redirectAction" >/manager/managerInfo/account.action?account.accountNO=${account.accountNO}</result>.


如果想传递多个参数用"&"符号来连接吗?NO,因为用"&"会在XML语法检查中报错,所以将"&"用"&amp;"来替换就行了!
如:
<result name="reload" type="redirectAction" >/manager/managerInfo/account.action?account.accountNO=${account.accountNO}&amp;account.balance=${account.balance}</result>.

猜你喜欢

转载自haoyiming.iteye.com/blog/1696530