黑马程序员——struts2学习笔记二(结果类型)

来源:互联网 发布:mac腾讯助手官方下载 编辑:程序博客网 时间:2024/06/15 02:58

-----------android培训java培训、java学习型技术博客、期待与您交流!------------

struts2结果类型

1、struts2框架已经在struts-default.xml文件中将常用的结果类型定义好,如下:

***************************************************************

<results-types>

            <results-typename="chain"class="com.opensymphony.xwork2.ActionChainResults"/>

            <results-typename="dispatcher"class="org.apache.struts2.dispatcher.ServletDispatcherResults"default="true"/>

            <results-typename="freemarker"class="org.apache.struts2.views.freemarker.FreemarkerResults"/>

            <results-typename="httpheader"class="org.apache.struts2.dispatcher.HttpHeaderResults"/>

            <results-typename="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResults"/>

            <results-typename="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResults"/>

            <results-typename="stream" class="org.apache.struts2.dispatcher.StreamResults"/>

            <results-typename="velocity"class="org.apache.struts2.dispatcher.VelocityResults"/>

            <results-typename="xslt"class="org.apache.struts2.views.xslt.XSLTResults"/>

            <results-typename="plainText"class="org.apache.struts2.dispatcher.PlainTextResults"/>

        </results-types>

***************************************************************

2、结果类型有什么用,怎么用?

 在< results name=…” type=”…”/>标签中有一个“type”的属性,是用来指定相应的结果类型,默认为转发;

results标签的别一种写法(标准写法):

<results name=”…” type=”…”>

   <param name=“…”>xx.jsp/xxaction/…</param>

</results>

因此结果类型就是用来处理action执行完后发送问题的JAVA,以下是几种常见的结果类型配置方法:

dispatcher(默认的):转发到JSP,配置方式:

***************************************************************

<results name=”…” type= “dispatcher”>

   <paramname=“location”>xx.jsp/</param>

</results>

***************************************************************

Param中的name”location”,原因为结果类型对应的类中已经定义好!

redirect:重定向到jsp,配置方式

***************************************************************

<results name=”…” type=”redirect”>

   <paramname=“location”>xx.jsp/ </param>

</results>

***************************************************************

③redirectAction:重定向到action,配置方式:

***************************************************************

<results name=”…” type=” redirectAction”>

   <paramname=“actionName”>[此外写需要定向到的action的名称,即<action/>标签中的name属性对应的值]</param>

<param name=“namespace”>[此外写需要定向到的action所在的名称空间]</param>

</results>

***************************************************************

3、全局结果类型<global-reults>:当多个action执行都有同一个结果类处理方式时可以通过配置全局结果类型来减少配置的重复,例如:

***************************************************************

<global-resultss>

< resultss name=”…” type=”……”>

   <paramname=“……”>……</param>

   ……

</ resultss >

</global- resultss >

***************************************************************

如果局部结果类型和全局结果类型同时存在,局部会将全局复盖。

局部结果类型作用于所在的action;全局则作用于整个包。

****************************2015年8月5日***********************************



0 0