11.Struts2_result概述

1.rusult:

1). result 是 action 节点的子节点
2). result 代表 action 方法执行后, 可能去的一个目的地
3). 一个 action 节点可以配置多个 result 子节点.
4). result 的 name 属性值对应着 action 方法可能有的一个返回值.

result name="index">/index.jsp</result>
5). result 一共有 2 个属性, 还有一个是 type: 表示结果的响应类型
6). result 的 type 属性值在 struts-default 包的 result-types 节点的 name 属性中定义. 

2.type常用的有值有:

  1. dispatcher(默认的): 转发. 同 Servlet 中的转发
  2. redirect: 重定向 
  3. redirectAction: 重定向到一个 Action
  4. chain: 转发到一个 Action

用法:

 1.redirectAction:重定向到一个 Action

            <!-- 结果返回"index"之后,将会重定向到 package中 namespace="/user" 且其中的 action的 name="testAction" -->
            <result name="index" type="redirectAction">
                <param name="actionName">testAction</param>
                <param name="namespace">/user</param>
            </result>
 

2.redirect: 重定向 

<result name="index" type="redirect">/atguigu/testAction.do</result>

注意:用法1中的代码和用法2中的代码作用一致,通过 redirect 的响应类型也可以便捷的实现 redirectAction 的功能!


3.chain: 转发到一个 Action

    	   <result name="test" type="chain">
       		 <param name="actionName">testAction</param>
       		 <param name="namespace">/user</param>
   	  </result>


4.dispatcher(默认的): 转发. 同 Servlet 中的转发
注意: 不能通过 type=dispatcher 的方式转发到一个 Action  
不能是:

<!-- 会报 404 异常 -->
<result name="test">/user/testAction.do</result>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值