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. git hg提交拉取

    工作总结web_acl 535 git clone “ssh://git@outergit.yonyou.com:49622/esn_web/web_acl.git" 600 git bra ...

  2. CSS 折角效果

    1 <style type="text/css"> .div1 { width: 200px; height: 200px; background-color: #ff ...

  3. ValueError: update only works with $ operators

    问题:在执行pymongo的update语句时,提示了ValueError: update only works with $ operators 脚本:db.user.update_one({&qu ...

  4. luoguP1090 合并果子 (贪心+优先队列)

    题目链接:https://www.luogu.org/problemnew/show/P1090 思路: 典型的贪心题,显然每次选择两个最小的堆合并最后耗费的体力最少,但每次合并之后都需要寻找最小的两 ...

  5. np.eye()

    今天在完成深度学习的相关编程作业的时候,发现代码中出现了一个关于np.eye()的函数,这个函数的用法非常的简单,但是在预制的代码中,这个函数的用法并非单单制造一个对角矩阵,而是通过其来将一个labe ...

  6. 使用HttpModule实现网址重写和HttpHandler实现页面静态化冲突的解决办法

    使用HttpModule实现网址重写和HttpHandler冲突的解决办法功能描述:1. 用HttpModule做了一个重写URL的功能,实现所有访问html的请求要经过httpModule处理,如果 ...

  7. [leetcode]124. Binary Tree Maximum Path Sum二叉树最大路径和

    Given a non-empty binary tree, find the maximum path sum. For this problem, a path is defined as any ...

  8. 使用maven管理引入jdk1.8

    需要在配置文件settings.xml中加入: <profile> <id>jdk-1.8</id> <activation> <activeBy ...

  9. php 下载生成word文件

    方案一 $html2 ='数字'; header("Content-type: application/octet-stream"); header("Accept-Ra ...

  10. discuz回贴通知插件实现-获取邮件内容

    //自定义钩子函数,命名:模块_函数名_output()或模块_函数名() //一个是模块执行完,模板输出前执行.一个是模块执行前 //post_reply_output函数会在所有post操作中都会 ...