天天看點

struts2 result type 類型

我們在使用struts2進行配置struts.xml的時候,<result>中有個tyep屬性用來配置跳轉類型

預設不寫時tyep="dispatcher",我們可以根據我們的需要選擇跳轉類型

例如:<result name="list" type="redirect">User_list</result>

這個result-type的具體類型可以在對應的struts2-croe-2.*.jar或者struts2源代碼中的struts-default.xml中找到,在這個檔案中找到<result-type>标簽,所有的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的執行與另外一個配置好的action串連起來。用第一個action的getter方法和第二個action的setter方法來完成action之間屬性的複制。 

    com.opensymphony.xwork2.ActionChainResult  

dispatcher     

    用來轉向JSP頁面,這是預設的結果類型,假如在action配置中沒有配置其他的結果類型,它就會被使用   

    org.apache.struts2.dispatcher.ServletDispatcherResult  

freemaker   

      處理FreeMarker模闆   

      org.apache.struts2.views.freemarker.FreemarkerResult  

httpheader   

      控制非凡HTTP行為的結果類型     

     org.apache.struts2.dispatcher.HttpHeaderResult  

redirect   

      重定向到一個URL     

      org.apache.struts2.dispatcher.ServletRedirectResult  

redirectAction   

    重定向到一個Action   

    org.apache.struts2.dispatcher.ServletActionRedirectResult  

stream   

      向浏覽器發送InputSream對象,通常用來處理檔案下載下傳,還可用于傳回AJAX資料   

     org.apache.struts2.dispatcher.StreamResult  

velocity   

      處理Velocity模闆   

     org.apache.struts2.dispatcher.VelocityResult  

xslt   

     處理XML/XLST模闆   

     org.apache.struts2.views.xslt.XSLTResult  

plainText   

      顯示原始檔案内容,例如檔案源代碼   

    org.apache.struts2.dispatcher.PlainTextResult

繼續閱讀