结果类型总结

结果类型:默认情况下是请求转发的.

在struts-default.xml下的默认包下可以看到:

       <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链上去.与redirectAction的区别:后者重定向到action里面.文件下载的时候result-type是stream的

重定向到action的话他还可以带个参数的啊,<param>子元素.这个看帮助文档和源代码都是可以知道的, struts.xml中也可以用${}这样的形式.这个很重要,必须要掌握的.

This result type takes the following parameters:

  • actionName (default) - the name of the action that will be redirect to
  • namespace - used to determine which namespace the action is in that we're redirecting to . If namespace is null, this defaults to the current namespace
  • supressEmptyParameters - optional boolean (defaults to false) that can prevent parameters with no values from being included in the redirect URL.

如:

<action name="action1" class="com.shengsiyuan.struts2.Action1">

<result name="success" type="redirectAction">
<param name="actionName">action2</param>
<param name="username">${username}</param>
<param name="password">${password}</param>
</result>

<interceptor-ref name="theInterceptor1"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>

注意到这里的${username}指的是将Action1里面的属性值传过去

redirectAction是有意义的,如当你添加的时候要转到页面的时候那肯定是重定向到一个Action里去,采取请求转发的方式完成表单内容的添加会造成内容的重复插入。采取重定向的方式实现数据的添加不会导致数据的重复插入。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yjsuge

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值