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

  • 相关阅读:
    Linux下date命令,格式化输出,时间设置
    Linux scp复制文件,不需要输入密码的技巧
    Linux中cp和scp命令的使用方法
    Linux定时任务系统 Cron
    Eclipse启动Tomcat后无法访问项目
    eclipse下tomcat插件配置说明
    RPM方式安装MySQL5.6和windows下安装mysql解压版
    shell script练习
    Eclipse Java注释模板设置详解
    mysql备份还原数据库
  • 原文地址:https://www.cnblogs.com/akatuki/p/4039801.html
Copyright © 2011-2022 走看看