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 跳转类型 result type=chain、dispatcher、redirect(redirect-action)的更多相关文章
- 学习Struts--Chap04:result中type属性dispatcher、redirect、redirectAction、chain的区别
1.Struts2框架中常用的结果类型的分析和比较 dispatcher:缺省的result类型,type默认是dispatcher内部转发.如果不写type类型只写一个名字的话,不单是type类型默 ...
- struts2跳转类型解析
struts 2 跳转类型 1.dispatcher dispatcher 为默认跳转类型.用于返回一个视图资源 xml代码 : <result name="success" ...
- Struts2 源码分析——调结者(Dispatcher)之执行action
章节简言 上一章笔者写关于Dispatcher类如何处理接受来的request请求.当然读者们也知道他并非正真的执行action操作.他只是在执行action操作之前的准备工作.那么谁才是正真的执行a ...
- struts2 Result Type四个常用转跳类型
Result的四个常用转跳类型分别为 Dispatcher 用来转向页面,是Struts的默认形式 Redirect 重定向到一个URL Chain 用来处理Action链 RedirectAc ...
- Struts2 语法--result type
result type: dispatcher,redirect:只能跳转到jsp,html之类的页面,dispatcher属于服务器跳转, redirect属于客户端跳转 chain: 等同于for ...
- Struts2 学习笔记 10 Result部分 part1
1.关于Result我们首先来学习一下结果类型 result type. 先来看struts.xml. struts.xml <?xml version="1.0" enco ...
- struts2 action result type类型
struts2 action result type类型 1.chain:用来处理Action链,被跳转的action中仍能获取上个页面的值,如request信息. com.opensymphony. ...
- struts2 result type类型
result标签中type的类型 类型 说明 chain 用于Action链式处理 dispatcher 用于整合JSP,是<result>元素默认的类型 freemarket 用来整合F ...
- Struts2 result type(结果类型)
转自:http://www.cnblogs.com/liaojie970/p/7151103.html 在struts2框架中,当action处理完之后,就应该向用户返回结果信息,该任务被分为两部分: ...
随机推荐
- hibernate事务隔离机制
事务的基本概念 ACID:A是atomicity(原子性),C是consistency(一致性),I是isolation(隔离性),D是durability(持久性) 事务隔离级别从低到高: 读取未提 ...
- MongoDB 集合命令
集合命令 创建语法如下 name是要创建的集合的名称 options是一个文档,用于指定集合的配置,选项参数是可选的,所以只需要到指定的集合名称 可以不手动创建集合,向不存在的集合中第一次加入数据 ...
- R画散点图、线型图、箱型图、直方图基本知识
1.导入数据 2.散点图 plot(iris[,1]~iris[,4],xlab='Length',ylab='Width',col='red',main='Length VS Width')
- MVC001之权限校验
参考网址:http://bbs.csdn.net/topics/370002739 http://blog.csdn.net/chenloveyue/article/details/7095522 h ...
- (mac环境)Appium安装了client包,但是提示no module named appium
背景 mac环境,使用pip install Appium-Python-Client已经安装了client包 问题 import appium,提示no module named appium ...
- WinScp获取一个文件
CD /d C:\Program Files (x86)\WinSCPWinSCP.exe /console /command "option batch continue" &q ...
- [Selenium]对弹出的Alert窗口进行操作
Alert alert = driver.switchTo().alert(); alert.accept();
- 原型工具之团队协作: Axure VS Mockplus
一款软件产品的诞生,必然会经历一个过程:需求分析.设计.开发.测试.上线.如此反复迭代.而设计阶段中,原型设计.制作.交流.审核.迭代,是软件设计和开发的重要保障. 简单的一段话,我们可以解读出很多隐 ...
- cmd 命令阻塞继续执行下面的命令的办法
例如在dos下查询硬盘序列号: 首先输入:diskpart-->select disk 0--> detail disk. 如果要在java下面直接查询可以写成一个bat文件写成下面形式: ...
- WebService安全加密
众所周知,WebService访问API是公开的,知道其URL者均可以研究与调用.那么,在只允许注册用户的WebService应用中,如何确保API访问和通信的安全性呢?本文所指的访问与通信安全性包括 ...