首页 > 代码库 > Servlet Filter 中init和destroy问题

Servlet Filter 中init和destroy问题

测试源码如下:

 1 package com.FilterTest.Filter; 2  3 import java.io.IOException; 4  5 import javax.servlet.Filter; 6 import javax.servlet.FilterChain; 7 import javax.servlet.FilterConfig; 8 import javax.servlet.ServletException; 9 import javax.servlet.ServletRequest;10 import javax.servlet.ServletResponse;11 12 public class TestFilter implements Filter {13 14     @Override15     public void init(FilterConfig filterConfig) throws ServletException {16         print("init");17     }18 19     @Override20     public void doFilter(ServletRequest request, ServletResponse response,21             FilterChain chain) throws IOException, ServletException {22         print("do filter");23         chain.doFilter(request, response);24         print("do filter End!");25     }26 27     @Override28     public void destroy() {29         print("destory!");30     }31     32     void print(String info){33         System.out.println(info+" Thread Name:"+Thread.currentThread().getName());34     }35 }

访问首页后调试控制台输出:

技术分享

未有init初始化和destroy销毁操作,暂时无解。

Servlet Filter 中init和destroy问题