Struts2 中result type屬性說明


首先看一下在struts-default.xml中對於result-type的定義:

<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鏈,被跳轉的action中仍能獲取上個頁面的值,如request信息.

dispatcher:用來轉向頁面,通常處理JSP.

freemaker:處理FreeMarker模板.

httpheader:控制特殊HTTP行為的結果類型.

redirect:重定向到一個URL,被跳轉的頁面中丟失傳遞的信息,如request.

redirectAction:重定向到一個Action,跳轉的頁面中丟失傳遞的信息.

stream:向瀏覽器發送InputSream對象,通常用來處理文件下載,還可用於返回AJAX數據.

velocity:處理Velocity模板.

xslt:處理XML/XLST模板.

plainText:顯示原始文件內容,例如文件源代碼.


重點說一下redirect和redirectAction的區別:

(1)使用redirect需要后綴名,使用redirect-action可以不需要后綴名.

(2)type="redirect"的值可以轉到其它命名空間下的action,而redirect-action只能轉到同一命名空下的action,因此它可以省略.do的后綴直接寫action的名稱.

 

參考:

http://blog.csdn.net/voyage_mh1987/article/details/5829163

http://onlylove.iteye.com/blog/154844

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM