首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

Struts2中result配备中各种视图转发类型

2012-07-08 
Struts2中result配置中各种视图转发类型struts2中result常见的几种转发类型:dispatcher(默认)即内部请求转

Struts2中result配置中各种视图转发类型

struts2中result常见的几种转发类型:dispatcher(默认)即内部请求转发,redirect重定向,redirectAction,plainText。
下面分别介绍以下几种方式。

1.dispatcher方式:
?? 这种方式是struts2中默认的转发类型,即内部请求转发,类似于forward的方式。这里不专门介绍。

2.redirect方式:
?? 首先看一下以下的配置代码片段:

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->1?<action?name="redirect">
2?????<result?type="redirect">/add.jsp</result>
3?</action>

?? 这时候,用户在浏览器中访问该action,例如,我们输入URL:http://localhost:8080/hello/redirect.action,当用户开始访问,我们会看到,浏览器的url地址变成:http://localhost:8080/hello/add.jsp。这说明,配置的确实是浏览器重定向的方式。

3.redirectAction方式:
?? 这种方式可以简单的理解成转向到另一个Action。这种配置往往在下面的情况下需要用到:例如,当管理员添加完一个用户后,系统自动跳转到用户列表的界面。那么我们进行如下配置:

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->1?<action?name="redirectAction">
2?????<result?type="redirectAction">listAction</result>
3?</action>

??? 而其中的listAction是用来控制显示所有用户的action。并且,该action必须和redirectAction处在同一个package下面。那么如果不在同一个包下,则需进行如下配置:

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->1?<result?type="redirectAction">
2?????<param?name="actionName">XXX</param>
3?????<param?name="namespace">YYY</param>
4?</result>

??? 其中XXX代表你要转向到的Action的名称,YYY代表该Action所在package对应的名称空间。

4.plainText方式
??? 这种方式一般来说使用的比较少,可能用到的情况:原样输出源代码。配置如下:

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->1?<action?name="abc"?>
2?????<result?type="plainText">
3?????????<param?name="location">/index.jsp</param>
4?????????<param?name="charSet">UTF-8</param>
5?????</result>
6?</action>

?? 这时,index.jsp的源代码则会以文本方式显示在浏览器中。


热点排行