struts2 result的type属性

目前只使用过以下3种,都是直接跳转到另一个action

 chain:

 写法:<result name="success" type="chain">nextAction</result> 

nextAction前面不加【/】斜线,上一个action中request中设置的值,在nextAction中可以取到

redirect:

写法:<result name="success" type="redirect">nextAction</result> 

nextAction前面加或不加【/】斜线都可以,上一个action中request中设置的值,会丢失,在nextAction中无法取到

但是可以使用【?】问号传参,注意【&】使用【&amp;】代替

<result name="success" type="redirect">nextAction?nextForm.property=${currentForm.property}&amp;nextForm.property=${current.property}</result>

nextAction中必须有nextForm的get和set方法,如果是属性的话也必须有get和set方法,才能取到值

private NEXTForm nextForm= new NEXTForm ();
public NEXTForm getNextForm() {
return nextForm;
}
public void setNextForm(NEXTForm nextForm) {
this.nextForm= nextForm;
}

redirectAction:

写法:<result name="success" type="redirectAction">nextAction</result> 

yourAction前面不加【/】斜线,上一个action中request中设置的值,会丢失,在nextAction中无法取到

但是可以使用【?】问号传参,注意【&】使用【&amp;】代替

<result name="success" type="redirect">nextAction?nextForm.property=${currentForm.property}&amp;nextForm.property=${current.property}</result>

nextAction中必须有nextForm的get和set方法,如果是属性的话也必须有get和set方法,才能取到值

private NEXTForm nextForm= new NEXTForm ();
public NEXTForm getNextForm() {
return nextForm;
}
public void setNextForm(NEXTForm nextForm) {
this.nextForm= nextForm;
}

注:redirect与redirect-action区别

一、使用redirect需要后缀名 使用redirect-action不需要后缀名 ,但是在我实际使用时redirect不加后缀名也可以,在同一个包下,不同包没有试过。
二、type="redirect" 的值可以转到其它命名空间下的action,而redirect-action只能转到同一命名空下的 action,因此它可以省略.action的后缀直接写action的名称。

原文地址:https://www.cnblogs.com/akatuki/p/4039801.html