struts2 跳转类型、 result type=chain、dispatcher、redirect(redirect-action)
来源:互联网 发布:淘宝女童模特小苹果 编辑:程序博客网 时间:2024/04/30 04:03
dispatcher 为默认跳转类型,用于返回一个视图资源(如:jsp)
Xml代码 :
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中的所有状态都不会存在。
处理方法:
(方法一):
Xml代码:
chain 用于把相关的几个action连接起来,共同完成一个功能。
Xml代码:
处于chain中的action属于同一个http请求,共享一个ActionContext
plaintextj 结果类型用于直接在页面上显示源代码
Xml代码:
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>
原文地址:http://jstree.iteye.com/blog/1464043
0 0
- 【转】struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)_forever
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- 2011-02-25 12:23 struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- struts struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)_forever
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- struts2 跳转类型、 result type=chain、dispatcher、redirect(redirect-action)
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)_forever
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- jasig-CAS架构
- linux内核字符串转换函数 -- linux内核
- 我的第一个php程序
- ubuntu 14下的双屏显示,安装 显卡驱动
- PHP 单一入口程序
- struts2 跳转类型、 result type=chain、dispatcher、redirect(redirect-action)
- c++pair的用法
- iOS开发那些事--iOS6 UI状态保持和恢复
- python中的requests使用
- 关于多张图片的上传处理方法
- 6个值得推荐的Android开源框架简介
- my.cf
- Ignatius and the Princess IV
- java!你为什么这么火!