码迷,mamicode.com
首页 > 其他好文 > 详细

Servlet Filter 中init和destroy问题

时间:2016-09-10 19:22:06      阅读:1253      评论:0      收藏:0      [点我收藏+]

标签:

测试源码如下:

 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     @Override
15     public void init(FilterConfig filterConfig) throws ServletException {
16         print("init");
17     }
18 
19     @Override
20     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     @Override
28     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问题

标签:

原文地址:http://www.cnblogs.com/LouisMing/p/5859977.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!