result是用于做输出的组建,用于向页面输出一些内容,转发重定向可以理解为特殊方式的输出,每一个result就是一个类
这些类都实现了共同的接口Result,struts2预置了10种类型的result,他们都被定义在struts-default.xml种
SSH项目->Referenced Libraries->struts2-core-2.5.16.jar中找到struts-default.xml,struts-default.xml约束文件第192行定义了十种result转发类型
<result-types>
<result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
<result-type name="dispatcher" class="org.apache.struts2.result.ServletDispatcherResult" default="true"/>
<result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>
<result-type name="httpheader" class="org.apache.struts2.result.HttpHeaderResult"/>
<result-type name="redirect" class="org.apache.struts2.result.ServletRedirectResult"/>
<result-type name="redirectAction" class="org.apache.struts2.result.ServletActionRedirectResult"/>
<result-type name="stream" class="org.apache.struts2.result.StreamResult"/>
<result-type name="velocity" class="org.apache.struts2.result.VelocityResult"/>
<result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
<result-type name="plainText" class="org.apache.struts2.result.PlainTextResult" />
<result-type name="postback" class="org.apache.struts2.result.PostbackResult" />
</result-types>
重点:chain dispatcher redirect redirectAction stream
Result的四个常用转跳类型分别为
Dispatcher 用来转向页面,是Struts的默认形式
Redirect 重定向到一个URL
Chain 用来处理Action链
RedirectAction 重定向到一个Action
还有以下几种不太常用
freemaker: 处理FreeMarker模板
httpheader: 控制特殊HTTP行为的结果类型
stream: 向浏览器发送InputSream对象,用来处理文件下载,还可用于返回AJAX数据
velocity : 处理Velocity模板
xsl: 处理XML/XLST模板
plaintext: 显示原始文件内容,例如文件源代码
转载于:https://www.cnblogs.com/1138720556Gary/p/11627687.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)