zoukankan      html  css  js  c++  java
  • 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的名称。

  • 相关阅读:
    全国疫情可视化地图(第三阶段)
    全国疫情可视化地图(第二阶段)
    JAVAWEB调用数据库显示图形化显示
    全国疫情可视化地图(第一阶段)
    第二周学习总结
    个人介绍及目前现状
    循环列表下练习循环子数组
    构建之法读书笔记(三)
    构建之法读书笔记(二)
    变叶木
  • 原文地址:https://www.cnblogs.com/akatuki/p/4039801.html
Copyright © 2011-2022 走看看