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

  • 相关阅读:
    pyinstaller 将 python 代码打包成执行文件
    python excel 处理 xlrd & xlwt &xlutils
    服务器重启后 Nvidia 环境错误
    py 编译so
    cv 读取宽高和画框
    libreOffice doc 转pdf
    gunicorn 使用
    asp.net 跬步篇(4) EnableSessionState设置 引起的框架集加载问题
    驱驾ViewState利剑—压缩ViewState
    asp.net 开发 跬步篇〔3〕.net 邮件批量发送
  • 原文地址:https://www.cnblogs.com/akatuki/p/4039801.html
Copyright © 2020-2023  润新知