<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    空間站

    北極心空

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      15 Posts :: 393 Stories :: 160 Comments :: 0 Trackbacks

    一個提交到服務器的處理通常可以分為兩個階段,第一個階段查詢服務器狀態(查詢或者更新數據庫),第二個階段選擇一個合適的結果頁面其返回給用戶(這里要講的Result的內容)。

     

    Struts2提供了對不同種類返回結果的支持,常見的有JSP,FreeMarker,Velocity等。

    Struts2支持的不同類型的返回結果為:

     

    名字

     

    說明

     

    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類型還包括JasperReports Plugin,專門用來處理JasperReport類型的報表輸出。

     

    在struts-default.xml文件中已經有了對于所有類型Result的定義:

    <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類型的時候使用dispatcher類型。

     

    定義一個Result值,

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

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

    </result>

    由于type默認值是dispatcher,所以這里不需要定義,另外name的默認值為success所以這里也不需要定義。

    上述代碼可以簡寫為:

    <result>

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

    </result>

    另外location參數也可以直接卸載result標簽內部,所以上述代碼的最簡單的寫法為:

    <result>/ThankYou.jsp</result>

     

    我們也可以定義多個不同的Result

    <action name="Hello">

     <result>/hello/Result.jsp</result>

     <result name="error">/hello/Error.jsp</result>

     <result name="input">/hello/Input.jsp</result>

    </action>

    上述代碼的含義為,名字為Hello的Action有三個返回結果,并且都是dispatcher類型(默認類型),這三個返回值的名字分別為success(默認值),error,input,對應的頁面的路徑分別為/hello/Result.jsp,/hello/Error.jsp,/hello/Input.jsp。

     

    有些時候我們需要一個定義在全局的Result,這個時候我們可以在package內部定義全局的Result,例如:

    <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>

     

    動態返回結果

    有些時候,只有當Action執行完璧的時候我們才知道要返回哪個結果,這個時候我們可以在Action內部定義一個屬性,這個屬性用來存儲Action執行完璧之后的Result值,例如:

    private String nextAction; 

    public String getNextAction() {

        return nextAction;

    }

     

    在strutx.xml配置文件中,我們可以使用${nextAction}來引用到Action中的屬性,通過${nextAction}表示的內容來動態的返回結果,例如:

    <action name="fragment" class="FragmentAction">

     <result name="next" type="redirect-action">${nextAction}</result>

    </action>

     

    上述Action的execute方法返回next的時候,還需要根據nextAction的屬性來判斷具體定位到哪個Action。

     

    在strutx.xml配置文件中,我們可以使用method=""來設置調用類的哪個方法,這樣就可以在一個JAVA類中使用不同的方法來實現不同的功能,就無需每個功能寫一類了,例如:

    <action name="fragment" class="FragmentAction" method="add">

          <result>/success.jsp</result>

    </action>

    posted on 2007-12-21 13:04 蘆葦 閱讀(3554) 評論(0)  編輯  收藏 所屬分類: Struts
    主站蜘蛛池模板: 97免费人妻无码视频| 久久久WWW成人免费精品| 久久精品视频免费播放| 亚洲精品无码成人片久久| 国产大片免费天天看| 亚洲无线码在线一区观看| 国产黄片不卡免费| 在线亚洲人成电影网站色www| 一级人做人爰a全过程免费视频| 亚洲成人影院在线观看| 深夜福利在线视频免费| 亚洲色婷婷一区二区三区| a毛片免费全部播放完整成| 亚洲AV无码不卡在线播放| 99视频在线精品免费| 亚洲第一二三四区| 成人影片麻豆国产影片免费观看| 亚洲色大成WWW亚洲女子| 国产免费私拍一区二区三区| 深夜a级毛片免费视频| 亚洲精品国产精品乱码视色 | 四虎1515hm免费国产| 日韩电影免费在线观看网址 | 免费无码VA一区二区三区| 亚洲视频精品在线观看| 一二三四免费观看在线视频中文版 | 午夜免费福利网站| 日本黄页网址在线看免费不卡| 亚洲熟妇丰满多毛XXXX| 最近中文字幕大全免费视频| 亚洲AV无码乱码麻豆精品国产| 国产a不卡片精品免费观看| a级特黄毛片免费观看| 亚洲美女aⅴ久久久91| 免费无遮挡无码视频网站| 久久国产美女免费观看精品| 亚洲色四在线视频观看| 黄a大片av永久免费| 99久久婷婷免费国产综合精品| 亚洲国产精品午夜电影| 日本一线a视频免费观看|