首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

java 日记过滤器

2012-07-23 
java 日志过滤器记录日志.LoggerFilter.javapackage com.easyweb.web.characterimport java.io.*import

java 日志过滤器

记录日志.

LoggerFilter.java

package com.easyweb.web.character;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
?* 全局日志记录过滤器(暂且不用,现在使用的是spring aop记录日志)
?* @author Administrator
?*
?*/
public class LoggerFilter implements Filter{
? private FilterConfig filterConfig = null;

??? public void doFilter(ServletRequest request, ServletResponse response,
????? FilterChain chain)
????? throws IOException, ServletException
??? {

????? long start = System.currentTimeMillis();
????? String address =?? request.getRemoteAddr();
????? String file = ((HttpServletRequest) request).getRequestURI();
????? chain.doFilter(request, response);

????? filterConfig.getServletContext().log(
????????? "User access! " +?????
????????? " User IP: " + address +?????
????????? " Resource: " + file +
????????? " Milliseconds used: " + (System.currentTimeMillis() - start)
????? );
????? //记录到数据库
??? }

??? public void destroy() { }

??? public void init(FilterConfig filterConfig) {
????? this.filterConfig = filterConfig;
??? }

}

热点排行