经过过滤器1前打印 "过滤器1执行了" ,然后经过过滤器1放行。
经过过滤器2前打印 "过滤器2执行了" ,然后经过过滤器2放行。
然后 资源执行
离开过滤器2前打印 "过滤器2离开了" ,然后经过过滤器2放行。
离开过滤器1前打印 "过滤器1离开了" ,然后经过过滤器1放行。
@WebFilter("/*")
public class FilterDemo6 implements Filter {
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
System.out.println("filterDemo6执行了...");
chain.doFilter(req, resp);
System.out.println("filterDemo6回来了...");
}
public void init(FilterConfig config) throws ServletException {
}
public void destroy() {
}
}
@WebFilter("/*")
public class FilterDemo17 implements Filter {
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
System.out.println("filterDemo7执行了...");
chain.doFilter(req, resp);
System.out.println("filterDemo7回来了...");
}
public void init(FilterConfig config) throws ServletException {
}
public void destroy() {
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
index.jsp....
<%
System.out.println("index.jsp....");
%>
</body>
</html>
* 过滤器先后顺序问题:
1. 注解配置:按照类名的字符串比较规则比较,值小的先执行
* 如: AFilter 和 BFilter,AFilter就先执行了。比如:FilterDemo6和FilterDemo7,FilterDemo6先执行
比如:FilterDemo6和FilterDemo17,FilterDemo17先执行
2. web.xml配置: <filter-mapping>谁定义在上边,谁先执行