结果类型:默认情况下是请求转发的.
在struts-default.xml下的默认包下可以看到:
<result-types>
<result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
<result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>
<result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>
<result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
<result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
<result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>
<result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>
<result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
<result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />
</result-types>
为chain的时候表明转到另外一个Action链上去.与redirectAction的区别:后者重定向到action里面.文件下载的时候result-type是stream的
重定向到action的话他还可以带个参数的啊,<param>子元素.这个看帮助文档和源代码都是可以知道的, struts.xml中也可以用${}这样的形式.这个很重要,必须要掌握的.
This result type takes the following parameters:
- actionName (default) - the name of the action that will be redirect to
- namespace - used to determine which namespace the action is in that we're redirecting to . If namespace is null, this defaults to the current namespace
- supressEmptyParameters - optional boolean (defaults to false) that can prevent parameters with no values from being included in the redirect URL.
如:
<action name="action1" class="com.shengsiyuan.struts2.Action1">
<result name="success" type="redirectAction">
<param name="actionName">action2</param>
<param name="username">${username}</param>
<param name="password">${password}</param>
</result>
<interceptor-ref name="theInterceptor1"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>
注意到这里的${username}指的是将Action1里面的属性值传过去
redirectAction是有意义的,如当你添加的时候要转到页面的时候那肯定是重定向到一个Action里去,采取请求转发的方式完成表单内容的添加会造成内容的重复插入。采取重定向的方式实现数据的添加不会导致数据的重复插入。