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常用的有值有:
- dispatcher(默认的): 转发. 同 Servlet 中的转发
- redirect: 重定向
- redirectAction: 重定向到一个 Action
- 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>
注意: 不能通过 type=dispatcher 的方式转发到一个 Action
不能是:
<!-- 会报 404 异常 -->
<result name="test">/user/testAction.do</result>