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的名称。

  • 相关阅读:
    Tomcat的startup.bat启动后显示乱码
    影响solr性能的一些因素(附使用经验)
    使用QQ传输大文件
    域名的接入备案和取消接入
    solr中Cache综述
    关于集群的一些概念
    RAMDISK 内存盘工具推荐
    实时监听input输入内容的N种方法
    jquery操作select下拉框的各种方法,获取选中项的值或文本,根据指定的值或文本选中select的option项等
    Vmware虚拟机三种网络模式详解
  • 原文地址:https://www.cnblogs.com/akatuki/p/4039801.html
Copyright © 2011-2022 走看看