Filter细节处理web.xml、Filte细节处理执行流程&生命周期
Filter细节处理web.xml
web.xml配置
<filter>
<filter-name>FilterDome1</filter-name>
<filter-class>ssr.web.filter.FilterDome1</filter-class>
</filter>
<filter-mapping>
<filter-name>FilterDome1</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Filte细节处理执行流程&生命周期
public class FilterDome1 implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
System.out.println("被执行了..");
chain.doFilter(request,response);
System.out.println("又回来了...");
}
@Override
public void destroy() {
}
}
<html>
<head>
<title>$Title$</title>
</head>
<body>
index.jsp....
<%
System.out.println("index.jsp....");
%>
</body>
</html>
<filter>
<filter-name>FilterDome1</filter-name>
<filter-class>ssr.web.filter.FilterDome1</filter-class>
</filter>
<filter-mapping>
<filter-name>FilterDome1</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
我们在来看生命周期
public class FilterDome1 implements Filter {
@Override
// 服务器启动都,会创建创建调用init
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
// 服务启动后 会执行
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
System.out.println("被执行了..");
chain.doFilter(request,response);
System.out.println("又回来了...");
}
@Override
// 正常关闭后执行...
public void destroy() {
}
}