• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            xiaoguozi's Blog
            Pay it forword - 我并不覺的自豪,我所嘗試的事情都失敗了······習慣原本生活的人不容易改變,就算現(xiàn)狀很糟,他們也很難改變,在過程中,他們還是放棄了······他們一放棄,大家就都是輸家······讓愛傳出去,很困難,也無法預料,人們需要更細心的觀察別人,要隨時注意才能保護別人,因為他們未必知道自己要什么·····
            提交服務器處理業(yè)務后結(jié)果返回頁面的處理,Struts2提供了對不同種類返回結(jié)果的支持,常見的有JSP,F(xiàn)reeMarker,Velocity等。

            struts.xml配置文件中result的語法:<result name="" type="">xxxxx</result>

            Struts2支持的不同類型的返回結(jié)果為:

            Chain Result-->type="chain"
            用來處理Action鏈

            Dispatcher Result -->type="dispatcher"
            用來轉(zhuǎn)向頁面,通常處理JSP

            FreeMarker Result -->type="freemarker"
            處理FreeMarker模板

            HttpHeader Result -->type="httpheader"
            用來控制特殊的Http行為

            Redirect Result -->type="redirect"
            重定向到一個URL

            Redirect Action Result -->type="redirectAction"
            重定向到一個Action

            Stream Result -->type="stream"
            向瀏覽器發(fā)送InputSream對象,通常用來處理文件下載

            Velocity Result -->type="velocity"
            處理Velocity模板

            XLST Result -->type="xslt"
            處理XML/XLST模板

            PlainText Result -->type="plainText"
            顯示原始文件內(nèi)容,例如文件源代碼


            另外第三方的result類型還包括JasperReports Plugin,專門用來處理JasperReport類型的報表輸出。

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

            Java 代碼

            1. <result-types>  
            2.  
            3.     <result-type name="chain"  
            4.  
            5.              class="com.opensymphony.xwork2.ActionChainResult"/>  
            6.  
            7.     <result-type name="dispatcher"  
            8.  
            9.              class="org.apache.struts2.dispatcher.ServletDispatcherResult"  
            10.  
            11.              default="true"/>  
            12.  
            13.     <result-type name="freemarker"  
            14.  
            15.              class="org.apache.struts2.views.freemarker.FreemarkerResult"/>  
            16.  
            17.     <result-type name="httpheader"  
            18.  
            19.              class="org.apache.struts2.dispatcher.HttpHeaderResult"/>  
            20.  
            21.     <result-type name="redirect"  
            22.  
            23.              class="org.apache.struts2.dispatcher.ServletRedirectResult"/>  
            24.  
            25.     <result-type name="redirectAction"  
            26.  
            27.              class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>  
            28.  
            29.     <result-type name="stream"  
            30.  
            31.              class="org.apache.struts2.dispatcher.StreamResult"/>  
            32.  
            33.     <result-type name="velocity"  
            34.  
            35.              class="org.apache.struts2.dispatcher.VelocityResult"/>  
            36.  
            37.     <result-type name="xslt"  
            38.  
            39.              class="org.apache.struts2.views.xslt.XSLTResult"/>  
            40.  
            41.     <result-type name="plainText"  
            42.  
            43.              class="org.apache.struts2.dispatcher.PlainTextResult" />  
            44.  
            45.     <!-- Deprecated name form scheduled for removal in Struts 2.1.0.  
            46.  
            47.          The camelCase versions are preferred. See ww-1707 -->  
            48.  
            49.     <result-type name="redirect-action"  
            50.  
            51.              class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>  
            52.  
            53.     <result-type name="plaintext"  
            54.  
            55.              class="org.apache.struts2.dispatcher.PlainTextResult" />  
            56.  
            57. </result-types>  

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

            Java 代碼

            1. <result name="success" type="dispatcher">  
            2.  
            3.     <param name="location">/myjsp.jsp</param>  
            4.  
            5. </result>  

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

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

            </result>


            由于type默認值是dispatcher,所以這里不需要定義,另外name的默認值為success所以這里也不需要定義。
            上述代碼可以簡寫為:

            Java 代碼

            1. <result>  
            2.  
            3.     <param name="location">/myjsp.jsp</param>  
            4.  
            5. </result>  

            <result>

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

            </result>




            另外location參數(shù)也可以直接卸載result標簽內(nèi)部(也就是無需再result里面使用),所以上述代碼的最簡單的寫法為:

            Java 代碼

            1. <result>/myjsp.jsp</result>  

            <result>/myjsp.jsp</result>



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

            Java 代碼

            1. <action name="Hello">  
            2.  
            3. <result>/hello/hello.jsp</result>  
            4.  
            5. <result name="error">/hello/error.jsp</result>  
            6.  
            7. <result name="input">/hello/input.jsp</result>  
            8.  
            9. </action>  

            <action name="Hello">

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

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

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

            </action>



            上 述代碼的含義為,名字為Hello的Action有三個返回結(jié)果,并且都是 dispatcher類型(默認類型),這三個返回值的名字分別為success(默認值),error,input(當輸入不通過時,action 方法返回input),對應的頁面的路徑分別為 /hello/result.jsp,/hello/error.jsp,/hello/input.jsp。

            有些時候我們需要一個定義在全局的result,這個時候我們可以在package內(nèi)部定義全局的result,例如:

            Java 代碼

            1. <global-results>  
            2.  
            3. <result name="error">/error.jsp</result>  
            4.  
            5. <result name="invalid.token">/error.jsp</result>  
            6.  
            7. <result name="login" type="redirect-action">login!input</result>  
            8.  
            9. </global-results>  

            <global-results>

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

            <result name="invalid.token">/error.jsp</result>

            <result name="login" type="redirect-action">login!input</result>

            </global-results>



            動態(tài)返回結(jié)果

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

            Java 代碼

            1. private String nextAction;  
            2.  
            3. public String getNextAction() {  
            4.  
            5.     return nextAction;  
            6.  
            7. }  

            private String nextAction;

            public String getNextAction() {

            return nextAction;

            }



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

            Java 代碼

            1. <action name="fragment" class="FragmentAction">  
            2.  
            3. <result name="next" type="redirect-action">${nextAction}</result>  
            4.  
            5. </action>  

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

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

            </action>



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


            在struts.xml配置文件中,我們可以使用method=""來設(shè)置調(diào)用類的哪個方法,這樣就可以在一個JAVA類中使用不同的方法來實現(xiàn)不同的功能,就無需每個功能寫一類了,例如:
            Java 代碼

            1. <action name="fragment" class="cn.com.web.FragmentAction" method="add">  
            2.       <result>/success.jsp</result>  
            3. </action> 
            posted on 2011-04-05 18:17 小果子 閱讀(526) 評論(0)  編輯 收藏 引用 所屬分類: 框架
            国产99久久九九精品无码| 亚洲国产高清精品线久久 | 久久久久亚洲av成人无码电影 | 无码任你躁久久久久久| 久久婷婷五月综合国产尤物app| 久久艹国产| 精品国产乱码久久久久久1区2区| 日本高清无卡码一区二区久久 | 久久精品国产清高在天天线| 亚洲午夜精品久久久久久app| 1000部精品久久久久久久久| 精产国品久久一二三产区区别| 亚洲天堂久久精品| 久久综合给合久久狠狠狠97色69| 亚洲精品WWW久久久久久| 香港aa三级久久三级| 久久综合狠狠综合久久综合88| 久久久久99这里有精品10| 精品久久综合1区2区3区激情| 国产精品久久久久久久久鸭| 久久亚洲精品国产精品| 少妇人妻综合久久中文字幕| 四虎影视久久久免费观看| 韩国三级中文字幕hd久久精品 | 伊人久久亚洲综合影院| 狠狠色丁香婷婷综合久久来来去 | 少妇久久久久久久久久| 久久久久久久波多野结衣高潮 | 久久黄视频| 国产精品欧美久久久久天天影视 | 一本一道久久综合狠狠老| 亚洲日本va午夜中文字幕久久| 久久久久无码专区亚洲av| 国产精品成人久久久久三级午夜电影| 69SEX久久精品国产麻豆| 久久久精品人妻一区二区三区蜜桃 | 亚洲伊人久久精品影院| 国内精品九九久久精品| 亚洲精品乱码久久久久66| 少妇久久久久久被弄高潮| 久久久久人妻精品一区 |