• Struts2 中result type属性说明


    Struts2 中result type属性说明


    首先看一下在struts-default.xml中对于result-type的定义:

    <result-types>
    <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
    <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
    <result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>
    <result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>
    <result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
    <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
    <result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>
    <result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>
    <result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
    <result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />
    </result-types>

    chain:用来处理Action链,被跳转的action中仍能获取上个页面的值,如request信息.

    dispatcher:用来转向页面,通常处理JSP.

    freemaker:处理FreeMarker模板.

    httpheader:控制特殊HTTP行为的结果类型.

    redirect:重定向到一个URL,被跳转的页面中丢失传递的信息,如request.

    redirectAction:重定向到一个Action,跳转的页面中丢失传递的信息.

    stream:向浏览器发送InputSream对象,通常用来处理文件下载,还可用于返回AJAX数据.

    velocity:处理Velocity模板.

    xslt:处理XML/XLST模板.

    plainText:显示原始文件内容,例如文件源代码.


    重点说一下redirect和redirectAction的区别:

    (1)使用redirect需要后缀名,使用redirect-action可以不需要后缀名.

    (2)type="redirect"的值可以转到其它命名空间下的action,而redirect-action只能转到同一命名空下的action,因此它可以省略.do的后缀直接写action的名称.

  • 相关阅读:
    算法设计策略
    挖金矿
    寻找假币
    循环赛日程表
    【三分钟视频教程】iOS开发中 Xcode 报 apple-o linker 错误的#解决方案#
    iOS问题#解决方案#之关于“application/x-www-form-urlencoded;charset=utf-8” not supported
    【两分钟教程】如何为博客园添加QQ咨询效果
    【两分钟教程】如何更改Xcode项目名称
    iOS数据库操作之coredata详细操作步骤
    svn使用笔记
  • 原文地址:https://www.cnblogs.com/wuxiang/p/3925321.html
Copyright © 2020-2023  润新知