-----------android培训、java培训、java学习型技术博客、期待与您交流!------------
struts2结果类型
1、struts2框架已经在struts-default.xml文件中将常用的结果类型定义好,如下:
***************************************************************
<results-types>
<results-type name="chain" class="com.opensymphony.xwork2.ActionChainResults"/>
<results-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResults"default="true "/>
<results-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResults"/>
<results-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResults"/>
<results-type name="redirect " class="org.apache.struts2.dispatcher.ServletRedirectResults"/>
<results-type name="redirectAction " class="org.apache.struts2.dispatcher.ServletActionRedirectResults"/>
<results-type name="stream " class="org.apache.struts2.dispatcher.StreamResults"/>
<results-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResults"/>
<results-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResults"/>
<results-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResults"/>
</results-types>
***************************************************************
2、结果类型有什么用,怎么用?
|
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日***********************************