Struts2框架使用(四)之关于Struts2的result配置

一、关于Struts的重定向,以及转发。

<result name="dispatcher" type="dispatcher">success.jsp</result>

在result标签中,name对应的是Action中返回的值。type默认属性是dispatcher 内部转发功能。

如果想要重定向,只需要将type属性改为redirect 重定向即可。

如果想要转发到其他Action的话,则需要改为chain 链条。

如果想要重定向到其他Action的话,可以改为redirectAction。

 

1,type 默认是 dispatcher 内部转发;
2,type 为 redirect 重定向;
3,type 为 chain 链条;
4,type 为 redirectAction 重定向到 action;
上面 4 个常用,一定要掌握;
其他

freemarker freemarker 模版
httpheader 返回一个已配置好的 HTTP 头信息响应
stream 将原始数据作为流传递回浏览器端,
velocity 呈现 Velocity 模板
xslt 该 XML 可以通过 XSL 模板进行转换
plaintext 返回普通文本类容
二、全局result

关于全局result,配置方法如下

<!-- 全局result,当在action中找不到该result时,就会来global中找 -->
      <global-results>
          <result name="err">err.jsp</result>
      </global-results>

一般可以用来陪着多个Action的共用result。例如:错误页面等。

posted @ 2017-12-17 16:42  糸色望  阅读(138)  评论(0编辑  收藏  举报