一。Chain Result:
这个result调用另外的一个action,连接自己的拦截器栈和result。
这个Result使用ActionMapperFactory提供的ActionMapper来重定位浏览器的URL来调用指定的action和(可选的)namespace. 这个Result比ServletRedirectResult要好.因为你不需要把URL编码成xwork.xml中配置的ActionMapper提供的模式. 这就是说你可以在任意点上改变URL模式而不会影响你的应用程序. 因此强烈推荐使用这个Result而不是标准的redirect result来解决重定位到某个action的情况.
调用{@link HttpServletResponse#sendRedirect(String) sendRedirect}方法来转到指定的位置. HTTP响应被告知使浏览器直接跳转到指定的位置(产生客户端的一个新请求). 这样做的结果会使刚刚执行的action(包括action实例,action中的错误消息等)丢失, 不再可用. 这是因为action是建立在单线程模型基础上的. 传递数据的唯一方式就是通过Session或者可以为Ognl表达式的web参数(url?name=value)
二。当使用type=“redirectAction” 或type=“redirect”提交到一个action并且需要传递一个参数时。这里是有区别的:
a.使用type=“redirectAction”时,结果就只能写Action的配置名,不能带有后缀:“.action”
Java代码
<action name="Login" class="steven.actions.LoginAction">
<result name="success" type="redirectAction">User?u_id=${loginBean.u_id}</result>
</action>
b.使用type=“redirect”时,结果应是action配置名+后缀名
Java代码
<action name="Login" class="steven.actions.LoginAction">
<result name="success" type="redirect">User.action?u_id=${loginBean.u_id}</result>
</action>
ps:1 redirect:action处理完后重定向到一个视图资源(如:jsp页面),请求参数全部丢失,action处理结果也全部丢失。
2 redirect-action:action处理完后重定向到一个action,请求参数全部丢失,action处理结果也全部丢失。
 
 
 
 
                
        这个result调用另外的一个action,连接自己的拦截器栈和result。
- actionName (默认) - 被调用的action的名字
- namespace - 被调用的action的名称空间. 如果名称空间为空,这默认为当前名称空间
- 
method - 用于指定目标action的另一个方法被调用. 如果空,默认为excute方法
 
这个Result使用ActionMapperFactory提供的ActionMapper来重定位浏览器的URL来调用指定的action和(可选的)namespace. 这个Result比ServletRedirectResult要好.因为你不需要把URL编码成xwork.xml中配置的ActionMapper提供的模式. 这就是说你可以在任意点上改变URL模式而不会影响你的应用程序. 因此强烈推荐使用这个Result而不是标准的redirect result来解决重定位到某个action的情况.
- ActionName (默认) - 重定位到的action名
- namespace - action的名称空间. 如果为null,则为当前名称空间
- 
 
调用{@link HttpServletResponse#sendRedirect(String) sendRedirect}方法来转到指定的位置. HTTP响应被告知使浏览器直接跳转到指定的位置(产生客户端的一个新请求). 这样做的结果会使刚刚执行的action(包括action实例,action中的错误消息等)丢失, 不再可用. 这是因为action是建立在单线程模型基础上的. 传递数据的唯一方式就是通过Session或者可以为Ognl表达式的web参数(url?name=value)
- location (默认) - action执行后跳转的地址.
- 
parse - 默认为true. 如果设置为false, location参数不会被当作Ognl表达式解析.
 
二。当使用type=“redirectAction” 或type=“redirect”提交到一个action并且需要传递一个参数时。这里是有区别的:
a.使用type=“redirectAction”时,结果就只能写Action的配置名,不能带有后缀:“.action”
Java代码
<action name="Login" class="steven.actions.LoginAction">
<result name="success" type="redirectAction">User?u_id=${loginBean.u_id}</result>
</action>
b.使用type=“redirect”时,结果应是action配置名+后缀名
Java代码
<action name="Login" class="steven.actions.LoginAction">
<result name="success" type="redirect">User.action?u_id=${loginBean.u_id}</result>
</action>
ps:1 redirect:action处理完后重定向到一个视图资源(如:jsp页面),请求参数全部丢失,action处理结果也全部丢失。
2 redirect-action:action处理完后重定向到一个action,请求参数全部丢失,action处理结果也全部丢失。
3 chain:action处理完后转发到一个action,请求参数全部丢失,action处理结果不会丢失。
Chain:基本用途是构造成一条动作链。前一个动作将控制权转交给后一个动作,而前一个动作的状态在后一个动作里仍然保持着。动作链由Chaining拦截器负责处理,因为这个拦截器是defaultStack拦截器栈的一份子,多以你随时都可以使用动作链。-
   <package name="p1"extends="struts-default">
      <action name="a1" class="...">
         <resulttype="chain">a2</result>
      </action>
      <action name="a2" class="...">
         <result type="chain">
           <paramname="actionName">a3</param>
           <paramname="namespace">/n2</param>
         </result>
      </action>
   </package>
   <package name="p2" namespace="/n2"extends="struts-default">
      <action name="a3" class="...">
         <result>/my.jsp</result>
      </action>
   </package> 
                   
                   
                   
                   
                             本文详细介绍了Struts2框架中的几种结果类型,包括ChainResult、RedirectActionResult与RedirectResult的区别和使用场景。并通过示例说明了redirectAction与redirect类型的参数传递区别及应用场景。
本文详细介绍了Struts2框架中的几种结果类型,包括ChainResult、RedirectActionResult与RedirectResult的区别和使用场景。并通过示例说明了redirectAction与redirect类型的参数传递区别及应用场景。
           
       
           
                 
                 
                 
                 
                 
                
               
                 
                 
                 
                 
                
               
                 
                 扫一扫
扫一扫
                     
              
             
                   5262
					5262
					
 被折叠的  条评论
		 为什么被折叠?
被折叠的  条评论
		 为什么被折叠?
		 
		  到【灌水乐园】发言
到【灌水乐园】发言                                
		 
		 
    
   
    
   
             
            


 
            