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

  • 相关阅读:
    [Node.js] CommonJS Modules
    [Node.js] npm init && npm install
    [AngularJS] Hijacking Existing HTML Attributes with Angular Directives
    [Node.js] Level 7. Persisting Data
    [Express] Level 5: Route file
    [Express] Level 5: Route Instance -- refactor the code
    [Express] Level 4: Body-parser -- Delete
    [Express] Level 4: Body-parser -- Post
    [Express] Level 3: Massaging User Data
    [Express] Level 3: Reading from the URL
  • 原文地址:https://www.cnblogs.com/564085446java/p/3822025.html
Copyright © 2020-2023  润新知