`
jackroomage
  • 浏览: 1196967 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类

struts2几种result type探究

 
阅读更多

struts2几种result type探究

 

 

Struts2 配置中的result的type作用 

 

 

 

redirectAction

    重定向到一个Action

    org.apache.struts2.dispatcher.ServletActionRedirectResult

 

 

redirect-action

    重定向到一个Action

    org.apache.struts2.dispatcher.ServletActionRedirectResult

 

应该是两种写法,作用一样!

 

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

 

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>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics