一个提交到服务器的处理一般能够分为两个阶段:
第一个阶段查询服务器状态(查询或者更新数据库)
第二个阶段选择一个合适的结果页面其返回给用户(这里要讲的Result的内容)。 java
名字
|
说明
|
Chain Result
|
用来处理Action链
|
Dispatcher Result
|
用来转向页面,一般处理JSP
|
FreeMarker Result
|
处理FreeMarker模板
|
HttpHeader Result
|
用来控制特殊的Http行为
|
Redirect Result
|
重定向到一个URL
|
Redirect Action Result
|
重定向到一个Action
|
Stream Result
|
向浏览器发送InputSream对象,一般用来处理文件下载
|
Velocity Result
|
处理Velocity模板
|
XLS Result
|
处理XML/XLST模板
|
PlainText Result
|
显示原始文件内容,例如文件源代码
|
S2PLUGINS:Tiles Result
|
结合Tile使用
|
<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" /> <!-- Deprecated name form scheduled for removal in Struts 2.1.0. The camelCase versions are preferred. See ww-1707 --> <result-type name="redirect-action" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/> <result-type name="plaintext" class="org.apache.struts2.dispatcher.PlainTextResult" /> </result-types>
<result name="success" type="dispatcher"> <param name="location">/ThankYou.jsp</param> </result>
<result> <param name="location">/ThankYou.jsp</param> </result>
<action name="Hello"> <result>/hello/Result.jsp</result> <result name="error">/hello/Error.jsp</result> <result name="input">/hello/Input.jsp</result> </action>
<global-results> <result name="error">/Error.jsp</result> <result name="invalid.token">/Error.jsp</result> <result name="login" type="redirect-action">Logon!input</result> </global-results>
private String nextAction; public String getNextAction() { return nextAction; }
<action name="fragment" class="FragmentAction"> <result name="next" type="redirect-action">${nextAction}</result> </action>