filter中的dispatcher標籤解析

2021-08-02 05:59:02 字數 1426 閱讀 6334

requestdispatcher提供兩個方法forward和include進行資源跳轉。

不同的是,如果使用forward跳轉則其後面的response輸出則不會執行,而用include來跳轉,則include的servlet執行完後,再返回到原來的servlet執行response的輸出(如果有)。

例項:

servlet a

requestdispatcher disp = request.getrequestdispatcher("b");

disp.forward(request, response);

system.out

.println("servlet a completed");

printwriter pw = response.getwriter();

pw.println("servlet a");

servlet b

printwriter pw = response.getwriter();

pw.println("servlet b");

輸出結果:

控制台:servlet a completed

頁面:servlet b

這表示在forward方法後的pw.println("servlet a")並未執行

如果將forward換成include的話,則結果為:

控制台:servlet a completed

頁面:servlet b servlet a

這表示include的servlet執行完後,再返回到原來的servlet執行response的輸出。

注意:如果在servlet b裡吧pw給close掉了的話,那servlet a 這裡就無法輸出了,則結果就和第乙個一樣。

400error-code>

/filter/error.jsplocation>

error-page>

404error-code>

/filter/error.jsplocation>

error-page>

500error-code>

/filter/error.jsplocation>

error-page>

意思是http請求響應的狀態碼只要是400、404、500三種狀態碼之一,容器就會將請求**到error.jsp下,這就觸發了一次error,走進了配置的dispatchfilter。需要注意的是注意一點的是,雖然把請求**到error.jsp是一次forward的過程,但是配置成forward並不會走dispatchfilter這個過濾器。

這四種dispatcher方式可以單獨使用,也可以組合使用,配置多個即可。

adotable中Filter的用法

當我們在運算元據集時,往往需要對資料進行篩眩例如 乙個名為customer的資料表,它具有custno custname country address phone state taxrate等字段,如果只想檢視國別為china或顧客號大於1000的顧客記錄,就需要對資料集進行過濾。經總結,有下面這...

Django的models中filter的各種用法

exact 精確等於 like aaa iexact 精確等於 忽略大小寫 ilike aaa contains 包含 like aaa icontains 包含 忽略大小寫 ilike aaa 但是對於sqlite來說,contains的作用效果等同於icontains。gt 大於 gte 大於等...

Hbase中Filter的使用

組裝查詢條件成hbase 過濾器 public static filter getorderqueryfilter querycondition qc if qc null qc.getpay time end null qc.getpay time end equals if qc null qc...