隨筆 - 6  文章 - 129  trackbacks - 0
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(14)

          隨筆檔案(6)

          文章分類(467)

          文章檔案(423)

          相冊

          收藏夾(18)

          JAVA

          搜索

          •  

          積分與排名

          • 積分 - 827240
          • 排名 - 49

          最新評論

          閱讀排行榜

          評論排行榜

          轉自:http://www.java2s.com/CN/Code/Java/Servlets/LoggingFilter.htm
          import 
          java.io.*;
          import javax.servlet.*;
          import javax.servlet.http.*;

          public final class LoggingFilter 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 = ((HttpServletRequestrequest).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;
            }
          }


          posted on 2009-12-21 10:35 Ke 閱讀(262) 評論(0)  編輯  收藏 所屬分類: othersjava
          主站蜘蛛池模板: 县级市| 景东| 疏勒县| 晋城| 汉阴县| 尚志市| 合川市| 玛多县| 巴彦县| 霍州市| 新野县| 隆回县| 合作市| 读书| 高雄县| 镇安县| 云浮市| 炎陵县| 浦江县| 洮南市| 大安市| 富宁县| 嘉禾县| 青川县| 梨树县| 阿克陶县| 天等县| 杨浦区| 泽普县| 绥棱县| 平凉市| 临海市| 沙洋县| 马边| 通州市| 光泽县| 微山县| 蓝山县| 湖北省| 都江堰市| 夏河县|