Struts2 Result配置詳解

說明:在前面的許多案例中我們所用到的Action基本都繼承自ActionSupport這個類,而在這個類中我們定義了五個字段:SUCCESS,NONE,ERROR,INPUT,LOGING。我們可以直接返回這些字段值,這些字段值實質是被定義成:String SUCCESS=”success”這樣的形式,所以我們只要在Result元素中用它們的小寫即可。
<result>標準完整形式如下:

<result name="success" type="dispatcher">

<param name="location">/default.jsp</param>

</result>

如果我們都採用默認的形式,最終可以簡寫成:<result>/default.jsp</result>

探討type類型

Type類型值

作用說明

對應類

chain

用來處理Action鏈

com.opensymphony.xwork2.ActionChainResult

dispatcher

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

org.apache.struts2.dispatcher.ServletDispatcherResult

redirect

重定向到一個URL

org.apache.struts2.dispatcher.ServletRedirectResult

redirectAction

重定向到一個Action

org.apache.struts2.dispatcher.ServletActionRedirectResult 

plainText

顯示源文件內容,如文件源碼

org.apache.struts2.dispatcher.PlainTextResult

freemarker

處理FreeMarker模板

org.apache.struts2.views.freemarker.FreemarkerResult

httpheader

控制特殊http行爲的結果類型

org.apache.struts2.dispatcher.HttpHeaderResult

stream

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

org.apache.struts2.dispatcher.StreamResult

velocity

處理Velocity模板

org.apache.struts2.dispatcher.VelocityResult

xslt  

  處理XML/XLST模板

org.apache.struts2.views.xslt.XSLTResult

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章