一個提交到服務器的處理一般能夠分爲兩個階段:
第一個階段查詢服務器狀態(查詢或者更新數據庫)
第二個階段選擇一個合適的結果頁面其返回給用戶(這裏要講的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>