1. 程式人生 > 其它 >JavaWeb19.2【Filter&Listener:過濾器Filter的執行流程和生命週期方法】

JavaWeb19.2【Filter&Listener:過濾器Filter的執行流程和生命週期方法】

 1 package com.haifei.web.filter;
 2 
 3 import javax.servlet.*;
 4 import javax.servlet.annotation.WebFilter;
 5 import java.io.IOException;
 6 
 7 /**
 8  * 過濾器細節細節 之 過濾器執行流程
 9  *      1. 執行過濾器
10  *         2. 執行放行後的資源
11  *         3. 回來執行過濾器放行程式碼下邊的程式碼
12  */
13 //@WebFilter("/*")
14 public class FilterDemo2 implements
Filter { 15 public void destroy() { 16 } 17 18 public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException { 19 20 //對request物件的請求訊息增強 21 22 System.out.println("FilterDemo2..."); 23 24 chain.doFilter(req, resp); //
IDEA"註解模式Filter"程式碼快速建立模板 自帶放行語句 25 26 //對response物件的響應訊息增強 27 28 System.out.println("FilterDemo2...回來了。。。"); 29 30 /* 31 http://localhost:8080/day19/index.jsp 32 33 FilterDemo2... 34 index.jsp 35 FilterDemo2...回來了。。。 36 */ 37 } 38 39 public
void init(FilterConfig config) throws ServletException { 40 41 } 42 43 }
 1 <%--
 2   Created by IntelliJ IDEA.
 3   User: yubaby
 4   Date: 2021/7/4
 5   Time: 21:35
 6   To change this template use File | Settings | File Templates.
 7 --%>
 8 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 9 <html>
10   <head>
11     <title>$Title$</title>
12   </head>
13   <body>
14   index.jsp
15 
16   <%
17     System.out.println("index.jsp");
18   %>
19   </body>
20 </html>