struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)

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中跳转问题的更多相关文章

  1. Struts2中的页面跳转

    内容源自:Struts2中的页面跳转 一.全局页面的设置如果<package>包中的一些action都返回success,并且返回的页面都是同一个JSP页面,这样就可以配置全局的结果页面. ...

  2. Struts2中动态方法的调用

    Struts2中动态方法调用就是为了解决一个action对应多个请求的处理,以免action太多. 主要有一下三种方法:指定method属性.感叹号方式和通配符方式.推荐使用第三种方式. 1.指定me ...

  3. Struts2中重定向和请求转发配置

    struts2中默认跳转为dispatcher请求转发 只能往jsp转发,跳转action报404 重定向 设置为redirect ,可以是jsp也可以是action <!--同一个包下的act ...

  4. jsp\struts1.2\struts2 中文件上传(转)

    jsp\struts1.2\struts2 中文件上传 a.在jsp中简单利用Commons-fileupload组件实现 b.在struts1.2中实现c.在sturts2中实现现在把Code与大家 ...

  5. Struts2 中result type属性说明

    Struts2 中result type属性说明 首先看一下在struts-default.xml中对于result-type的定义: <result-types><result-t ...

  6. 【转】Struts2中的MethodFilterInterceptor(转)

    这是一个Struts2.1.8.1应用,代码如下 首先是web.xml文件 view plaincopy to clipboardprint?01.<?xml version="1.0 ...

  7. struts2中token防止重复提交表单

    struts2中token防止重复提交表单 >>>>>>>>>>>>>>>>>>>&g ...

  8. Struts2中通配符

    1.Struts2中通配符可通过请求的url路径来确定包.类.方法.返回值名. 如 <action name="*_*_*_*" class="cn.javass. ...

  9. struts2中的json

    这里放一个转载的struts2中json的详细应用和范例, http://yshjava.iteye.com/blog/1333104,这是个人在网上看到的很用心也很详细的一份关于struts2中js ...

随机推荐

  1. java中面向对象的一些知识(二)

    一. 封装的讲解 什么是封装?为什么要封装?怎么实现封装? 封装的目的是为了提高程序的安全性.封装就是把不想让第三者看的属性,方法隐藏起来. 封装的实现方法是: 1.修改属性的可见性,限制访问. 2. ...

  2. How to see the "real" available resources ?

    Hi, Hope this will help you : nova hypervisor-stats It will return the statistics of the Hypervisor ...

  3. Hamming Distance

    The Hamming distance between two integers is the number of positions at which the corresponding bits ...

  4. win10 安装framework3.5

    win+x 点击命令提示符(个管理员) 输入dism.exe /online /enable-feature /featurename:NetFX3 /Source:H:\sources\sxs(解压 ...

  5. 排序map

    1.根据map的值,升序排序 Map<String, Integer> map = new TreeMap<String, Integer>(); map.put(" ...

  6. IE8下导入EXCEL数据传到客户端以附件下载

    IE8下导入EXCEL数据传到客户端以附件下载方式出现,而不显示数据,解决方法:以text/html格式返回. HttpResponseMessage message = new HttpRespon ...

  7. 开发webservice的方式

        什么是 web 服务? web 服务是对应用程序功能的网络访问接口,它是使用标准 Internet 技术构建的. 我们目前看到的部署在 Internet 上的 web 服务都是 HTML 网站 ...

  8. 何为SSH协议?

    该文来自百度百科,自我收藏. SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Network Working Group)所制定:SSH 为建立在应用层基础上的安全协议.SSH ...

  9. (3)WebApi客户端调用

    1.创建一个应用台控制程序,可以把Model的引用,用下面的方法拖拽上来(解决方案里没有这个文件,只是这个文件的引用)  2.Program.cs using System; using System ...

  10. llvm-summary

    llvm 学习总结 Type define int类型 IntegerType::get(mod->getContext(), 32) long类型 IntegerType::get(mod-& ...