• <button id="2q4wy"><menu id="2q4wy"></menu></button>
    <button id="2q4wy"><menu id="2q4wy"></menu></button><button id="2q4wy"></button>
  • <button id="2q4wy"></button>
  • <li id="2q4wy"></li>
  • <li id="2q4wy"></li>
    <button id="2q4wy"></button>
  • <button id="2q4wy"><xmp id="2q4wy">
  • <li id="2q4wy"><tt id="2q4wy"></tt></li>
  • 當前位置: 首頁(yè) > 講師博客 > 講師博文
    廣告1
    內置攔截器說(shuō)明
    時(shí)間:2015-04-25     作者:

     理解攔截器

    1.1.    什么是攔截器:

    攔截器,在A(yíng)OP(Aspect-Oriented Programming)中用于在某個(gè)方法或字段被訪(fǎng)問(wèn)之前,進(jìn)行攔截然后在之前或之后加入某些操作。攔截是AOP的一種實(shí)現策略。

    在Webwork的中文文檔的解釋為——攔截器是動(dòng)態(tài)攔截Action調用的對象。它提供了一種機制可以使開(kāi)發(fā)者可以定義在一個(gè)action執行的前后執行的代碼,也可以在一個(gè)action執行前阻止其執行。同時(shí)也是提供了一種可以提取action中可重用的部分的方式。

    談到攔截器,還有一個(gè)詞大家應該知道——攔截器鏈(Interceptor Chain,在Struts 2中稱(chēng)為攔截器棧Interceptor Stack)。攔截器鏈就是將攔截器按一定的順序聯(lián)結成一條鏈。在訪(fǎng)問(wèn)被攔截的方法或字段時(shí),攔截器鏈中的攔截器就會(huì )按其之前定義的順序被調用。

    1.2.    攔截器的實(shí)現原理:

    大部分時(shí)候,攔截器方法都是通過(guò)代理的方式來(lái)調用的。Struts 2的攔截器實(shí)現相對簡(jiǎn)單。當請求到達Struts 2的ServletDispatcher時(shí),Struts 2會(huì )查找配置文件,并根據其配置實(shí)例化相對的攔截器對象,然后串成一個(gè)列表(list),最后一個(gè)一個(gè)地調用列表中的攔截器。

    2.    攔截器的配置

    Struts 2已經(jīng)為您提供豐富多樣的,功能齊全的攔截器實(shí)現。大家可以至struts2的jar包內的struts-default.xml查看關(guān)于默認的攔截器與攔截器鏈的配置。

    Struts2(XWork)提供的攔截器的功能說(shuō)明: 
    攔截器

    名字

    說(shuō)明

    1、攔截器:Alias Interceptor

         名字:alias

         說(shuō)明:在不同請求之間將請求參數在不同名字件轉換,請求內容不變

    2、攔截器:Chaining Interceptor

          名字:chain

          說(shuō)明:讓前一個(gè)Action的屬性可以被后一個(gè)Action訪(fǎng)問(wèn),現在和chain類(lèi)型的result()結合使用。

    3、攔截器:Checkbox Interceptor

         名字:checkbox
       
          說(shuō)明:添加了checkbox自動(dòng)處理代碼,將沒(méi)有選中的checkbox的內容設定為false,而html默認情況下不提交沒(méi)有選中的checkbox。

    4、攔截器:Cookies Interceptor

         名字:cookies

         說(shuō)明:使用配置的name,value來(lái)是指cookies

    5、攔截器:Conversion Error Interceptor

          名字:conversionError

          說(shuō)明:將錯誤從ActionContext中添加到Action的屬性字段中。

    6、攔截器:Create Session Interceptor

          名字:createSession

          說(shuō)明:自動(dòng)的創(chuàng )建HttpSession,用來(lái)為需要使用到HttpSession的攔截器服務(wù)。

    7、攔截器:Debugging Interceptor

          名字:debugging

          說(shuō)明:提供不同的調試用的頁(yè)面來(lái)展現內部的數據狀況。

    8、攔截器:Execute and Wait Interceptor

          名字:execAndWait

          說(shuō)明:在后臺執行Action,同時(shí)將用戶(hù)帶到一個(gè)中間的等待頁(yè)面。

    9、攔截器:Exception Interceptor

         名字:exception

          說(shuō)明:將異常定位到一個(gè)畫(huà)面

    10、攔截器:File Upload Interceptor

           名字:fileUpload

            說(shuō)明:提供文件上傳功能

    11、攔截器:I18n Interceptor

            名字:i18n

            說(shuō)明:記錄用戶(hù)選擇的locale

    12、攔截器:Logger Interceptor 

            名字:logger

           說(shuō)明:輸出Action的名字

    13、攔截器:Message Store Interceptor

           名字:store

            說(shuō)明:存儲或者訪(fǎng)問(wèn)實(shí)現ValidationAware接口的Action類(lèi)出現的消息,錯誤,字段錯誤等。

    14、攔截器:Model Driven Interceptor

           名字:model-driven

            說(shuō)明:如果一個(gè)類(lèi)實(shí)現了ModelDriven,將getModel得到的結果放在Value Stack中。

    15、攔截器:Scoped Model Driven

           名字:scoped-model-driven

           說(shuō)明:如果一個(gè)Action實(shí)現了ScopedModelDriven,則這個(gè)攔截器會(huì )從相應的Scope中取出model調用Action的setModel方法將其放入Action內部。

    16、攔截器:Parameters Interceptor

            名字:params

             說(shuō)明:將請求中的參數設置到Action中去。

    17、攔截器:Prepare Interceptor

           名字:prepare

            說(shuō)明:如果Acton實(shí)現了Preparable,則該攔截器調用Action類(lèi)的prepare方法。

    18、攔截器:Scope Interceptor

           名字:scope

            說(shuō)明:將Action狀態(tài)存入session和application的簡(jiǎn)單方法。

    19、攔截器:Servlet Config Interceptor

            名字:servletConfig

            說(shuō)明:提供訪(fǎng)問(wèn)HttpServletRequest和HttpServletResponse的方法,以Map的方式訪(fǎng)問(wèn)。

    20、攔截器:Static Parameters Interceptor

            名字:staticParams

            說(shuō)明:從struts.xml文件中將中的中的內容設置到對應的Action中。

    21、攔截器:Roles Interceptor

            名字:roles

             說(shuō)明:確定用戶(hù)是否具有JAAS指定的Role,否則不予執行。

    22、攔截器:Timer Interceptor

           名字:timer

           說(shuō)明:輸出Action執行的時(shí)間

    23、攔截器:Token Interceptor

            名字:token

            說(shuō)明:通過(guò)Token來(lái)避免雙擊

    24、攔截器:Token Session Interceptor

            名字:tokenSession

            說(shuō)明:和Token Interceptor一樣,不過(guò)雙擊的時(shí)候把請求的數據存儲在Session中

    25、攔截器:Validation Interceptor

            名字:validation

            說(shuō)明:使用action-validation.xml文件中定義的內容校驗提交的數據。

    26、攔截器:Workflow Interceptor

            名字:workflow

            調用Action的validate方法,一旦有錯誤返回,重新定位到INPUT畫(huà)面

    27、攔截器:Parameter Filter Interceptor

           名字:N/A

            說(shuō)明:從參數列表中刪除不必要的參數

    28、攔截器:Profiling Interceptor

            名字:profiling

            說(shuō)明:通過(guò)參數激活profile


    在struts.xml文件中定義攔截器,攔截器棧: 

            

            

            

            

            

                 

                 

            

            

            ......

    咨詢(xún)電話(huà):
    0571-86155444
    咨詢(xún)熱線(xiàn):
    • 微信:13857108608
    聯(lián)系我們
    蜜芽亚洲av无码精品色午夜_久久免费国产AⅤ网_一本大道香蕉高清久久_精品久久久久久亚洲
  • <button id="2q4wy"><menu id="2q4wy"></menu></button>
    <button id="2q4wy"><menu id="2q4wy"></menu></button><button id="2q4wy"></button>
  • <button id="2q4wy"></button>
  • <li id="2q4wy"></li>
  • <li id="2q4wy"></li>
    <button id="2q4wy"></button>
  • <button id="2q4wy"><xmp id="2q4wy">
  • <li id="2q4wy"><tt id="2q4wy"></tt></li>