已配置結果類型名 | 類 名 | 描 述 |
dispatcher | org.apache.struts2.dispatcher. ServletDispatcherResult | 預設結果類型,用來呈現JSP頁面 |
---|---|---|
chain | com.opensymphony.xwork2. ActionChainResult | 将action和另外一個action連結起來 |
freemarker | org.apache.struts2.views.freemarker. FreemarkerResult | 呈現Freemarker模闆 |
httpheader | org.apache.struts2.dispatcher. HttpHeaderResult | 傳回一個已配置好的HTTP頭資訊響應 |
redirect | org.apache.struts2.dispatcher. ServletRedirectResult | 将使用者重定向到一個已配置好的URL |
redirectAction | org.apache.struts2.dispatcher. ServletActionRedirectResult | 将使用者重定向到一個已定義好的action |
stream | org.apache.struts2.dispatcher. StreamResult | 将原始資料作為流傳遞回浏覽器端, 該結果類型對下載下傳的内容和圖檔非常有用 |
velocity | org.apache.struts2.dispatcher. VelocityResult | 呈現Velocity模闆 |
xslt | org.apache.struts2.views.xslt. XSLTResult | 呈現XML到浏覽器, 該XML可以通過XSL模闆進行轉換 |
plaintext | org.apache.struts2.dispatcher. PlainTextResult | 傳回普通文本類容 |
以上是struts2的幾種常見result-type的類型。接下來做一個詳細介紹:
1. dispatcher
用來轉向頁面,通常處理JSP
org.apache.struts2.dispatcher.ServletDispatcherResult
2. chain
用來處理Action鍊,被跳轉的action中仍能擷取上個頁面的值,如request資訊。
com.opensymphony.xwork2.ActionChainResult
3. freemaker
處理FreeMarker模闆
org.apache.struts2.views.freemarker.FreemarkerResult
4 .httpheader
控制特殊HTTP行為的結果類型
org.apache.struts2.dispatcher.HttpHeaderResult
5. stream
向浏覽器發送InputSream對象,通常用來處理檔案下載下傳,還可用于傳回AJAX資料
org.apache.struts2.dispatcher.StreamResult
6. velocity
處理Velocity模闆
org.apache.struts2.dispatcher.VelocityResult
7. xslt
處理XML/XLST模闆
org.apache.struts2.views.xslt.XSLTResult
8. plainText
顯示原始檔案内容,例如檔案源代碼
org.apache.struts2.dispatcher.PlainTextResult
9. redirect
重定向到一個URL ,被跳轉的頁面中丢失傳遞的資訊,如request
org.apache.struts2.dispatcher.ServletRedirectResult
10 redirect-action
重定向到一個Action ,跳轉的頁面中丢失傳遞的資訊,如request
org.apache.struts2.dispatcher.ServletActionRedirectResult
*******************************************************************************************************************************************8
注:redirect與redirect-action差別
一、使用redirect需要字尾名 使用redirect-action不需要字尾名
二、type="redirect" 的值可以轉到其它命名空間下的action,而redirect-action隻能轉到同一命名空下的 action,是以它可以省略.action的字尾直接寫action的名稱。
如:
(1) redirect傳遞參數
<result name="success" type="redirect">viewTask.action</result>
<result name="success" type="redirect-action">viewTask</result>
(2) 附:redirect-action 傳遞參數
<action name="enterpreinfo" class="preinfoBusinessAction" method="enterPreinfoSub">
<result name="success" type="redirect-action">
showpreinfo?preinfo.order_number=${preinfo.order_number}&preinfo.company_name=${preinfo.company_name}
</result>
<result name="error" type="redirect">
<param name="location">/error.jsp</param>
</result>
</action>
因為使用了redirect-action,是以要注意不能将 showpreinf?preinfo.order_number=${preinfo.order_number}寫成 showpreinf.action?preinfo.order_number=${preinfo.order_number}
其中${}為EL表達式,擷取action:enterpreinfo中屬性的值;在這個配置檔案裡,多個參數的連接配接符使用了"&",但XML的文法規範,應該使用"&"代替"&",原理和HTML中的轉義相同,開始沒有注意,在struts分析配置檔案時,總是報出這樣的錯誤:
參考位址:
http://wangguorui89.iteye.com/blog/1105570
http://blog.knowsky.com/188302.htm
http://blog.csdn.net/etttttss/article/details/7484915