dispatcher 为默认跳转类型,用于返回一个视图资源(如:jsp) 
Xml代码 :

<result name="success">/main.jsp</result> 
<result name="success">/main.jsp</result> 
以上写法使用了两个默认,其完整的写法为: 
<result name="success" type="dispatcher"> 
        <param name="location">/maini.jsp</param> 
</result>

用于页面转发,页面跳转过程一直是同一个线程,Action中的数据一直保存在。 
location只能是页面,不能是另一个action(可用type="chain"解决)。

redirect 类型用于重定向到一个页面,另一个action或一个网址。 
Xml代码:

<result name="success" type="redirect">aaa.jsp</result> 
<result name="success" type="redirect">bbb.action</result> 
<result name="success" type="redirect">www.baidu.com</result>

缺点:redirect把一个http返回码(SUCCESS)以及返回的页面位置一起重新发给web服务器,容纳后由web服务器产生一个新的HTTP请求,就会产生一个新的线程,保存在原来Action执行的线程中的数据就无法访问。 
所以,result需要包含Action的数据,那么redirect不是一个可行的办法。因为新的HTTP请求时在Servlet容器的新的线程中处理的,ActionContext中的所有状态都不会存在。

处理方法:

(方法一): 
<result name="topic" type="redirect">/topicAction!findTopics.do?topicId=${topicId}</result> 
(方法二): 
<result name="topic" type="redirect-action"> 
<param name="actionName">findTopics</param> 
<param name="topicId">${topicId}</param> 
</result>

redirect-action 结果类型使用ActionMapperFactory提供的ActionMapper来重定向请求到另外一个action 
Xml代码:

<result name="err" type="redirect-action"> 
    <param name="actionName">重定向的Action名</param> 
     <param name="namespace">重定向Action所在的名字空间</param> 
</result> 
redirect和redirect-action两种结果类型在使用上其实并没有什么区别,只是写法不同而已。

chain 用于把相关的几个action连接起来,共同完成一个功能。 
Xml代码:

<action name="step1" class="test.Step1Action"> 
     <result name="success" type="chain">step2.action</result> 
</action> 
<action name="step2" class="test.Step2Action"> 
<result name="success">finish.jsp</result> 
</action> 
处于chain中的action属于同一个http请求,共享一个ActionContext

plaintextj 结果类型用于直接在页面上显示源代码

Xml代码:

<result name="err" type="plaintext"> 
    <param name="location">具体的位置</param> 
    <param name="charSet">字符规范(如GBK)</param> 
</result>

struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)的更多相关文章

  1. 学习Struts--Chap04:result中type属性dispatcher、redirect、redirectAction、chain的区别

    1.Struts2框架中常用的结果类型的分析和比较 dispatcher:缺省的result类型,type默认是dispatcher内部转发.如果不写type类型只写一个名字的话,不单是type类型默 ...

  2. struts2跳转类型解析

    struts 2 跳转类型 1.dispatcher  dispatcher 为默认跳转类型.用于返回一个视图资源 xml代码 : <result name="success" ...

  3. Struts2 源码分析——调结者(Dispatcher)之执行action

    章节简言 上一章笔者写关于Dispatcher类如何处理接受来的request请求.当然读者们也知道他并非正真的执行action操作.他只是在执行action操作之前的准备工作.那么谁才是正真的执行a ...

  4. struts2 Result Type四个常用转跳类型

    Result的四个常用转跳类型分别为 Dispatcher 用来转向页面,是Struts的默认形式 Redirect   重定向到一个URL Chain  用来处理Action链 RedirectAc ...

  5. Struts2 语法--result type

    result type: dispatcher,redirect:只能跳转到jsp,html之类的页面,dispatcher属于服务器跳转, redirect属于客户端跳转 chain: 等同于for ...

  6. Struts2 学习笔记 10 Result部分 part1

    1.关于Result我们首先来学习一下结果类型 result type. 先来看struts.xml. struts.xml <?xml version="1.0" enco ...

  7. struts2 action result type类型

    struts2 action result type类型 1.chain:用来处理Action链,被跳转的action中仍能获取上个页面的值,如request信息. com.opensymphony. ...

  8. struts2 result type类型

    result标签中type的类型 类型 说明 chain 用于Action链式处理 dispatcher 用于整合JSP,是<result>元素默认的类型 freemarket 用来整合F ...

  9. Struts2 result type(结果类型)

    转自:http://www.cnblogs.com/liaojie970/p/7151103.html 在struts2框架中,当action处理完之后,就应该向用户返回结果信息,该任务被分为两部分: ...

随机推荐

  1. FP-growth算法高效发现频繁项集(Python代码)

    FP-growth算法高效发现频繁项集(Python代码) http://blog.csdn.net/leo_xu06/article/details/51332428

  2. proxychains 安装

    一.安装下载源码: git clone https://github.com/rofl0r/proxychains-ng 编译和安装: cd proxychains-ng ./configure -- ...

  3. docker registry2

    https://blog.csdn.net/mideagroup/article/details/52052618

  4. jquery 判断checkbox是否被选中问题

    1.jquery库2以上 $("#checkbox_check").click(function(){ alert($(this).prop("checked" ...

  5. java script 模拟鼠标事件

    try { var selector1 = "._3-8y:first-child"; var evt = document.createEvent("MouseEven ...

  6. java中checked和unchecked 异常处理

    有两种类型的异常:一种是checked异常一种是unchecked异常,在这篇文章中我们将利用实例来学习这两种异常,checked的异常和unchecked异常最大的区别就是checked去唱是在编译 ...

  7. linux 用户管理(3)----查看用户登录时间以及命令历史

    1.查看当前登录用户信息 who命令: who缺省输出包括用户名.终端类型.登陆日期以及远程主机. who /var/log/wtmp 可以查看自从wtmp文件创建以来的每一次登陆情况 (1)-b:查 ...

  8. nyoj86-找球号(一) 【set 二分查找 hash】

    http://acm.nyist.net/JudgeOnline/problem.php?pid=86 找球号(一) 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 ...

  9. 图片添加热点MAP之后连接无效的解决方法

    好些接触网店的同事都会遇到这个问题:就是明明给图片添加了热点超链接,但是点击图片就是没反应. 其实这个问题就是热点冲突,也就是说这个页面中至少有2个名称相同的热点导致热点冲突无法正确加载. 谷歌浏览器 ...

  10. .net为图片添加水印(转) jpg png和gif格式

    .net为图片添加水印(转) jpg png和gif格式 .net为图片添加水印(转) jpg png和gif格式,转自csdn的hyde82,现在跟大家一起来分享下: 利 用.net中System. ...