快速业务通道

Servlet过滤器介绍之原理分析 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-17
OF_DAY);       if (isUnusualTime(currentTime, startTime, endTime)) {         context.log("WARNING: " + req.getRemoteHost() + " accessed "            + req.getRequestURL() + " on "            + formatter.format(calendar.getTime()));         // The log file is under <CATALINA_HOME>/logs.One log per day.       }       chain.doFilter(request, response);       System.out           .println("Within SimpleFilter2:Filtering the Response...");     } catch (IOException ioe) {       ioe.printStackTrace();     } catch (ServletException se) {       se.printStackTrace();     }    }    public void destroy() {}    // Is the current time between the start and end    // times that are marked as abnormal access times?    private boolean isUnusualTime(int currentTime, int startTime, int endTime) {     // If the start time is less than the end time (i.e.,     // they are two times on the same day), then the     // current time is considered unusual if it is     // between the start and end times.     if (startTime < endTime) {       return ((currentTime >= startTime) && (currentTime < endTime));     }     // If the start time is greater than or equal to the     // end time (i.e., the start time is on one day and     // the end time is on the next day), then the current     // time is considered unusual if it is NOT between     // the end and start times.     else {       return (!isUnusualTime(currentTime, endTime, startTime));     }    } }

web.xml设置不变。

关于Tomcat日志处理,这里补充介绍一下。config.getServletContext().log("log message")会将日志信息写入<CATALINA_HOME>/logs文件夹下,文件名应该为 localhost_log.2007-03-04.txt这样的形式(按日期每天产生一个,第二天可以看见)。要 得到这样一个日志文件,应该在server.xml中有:

<Logger className="org.apache.catalina.logger.FileLogger" prefix="catalina_log." suffix=".txt" timestamp="true"/>

本文出自 “子 孑” 博客,请务必保留此出处 http://zhangjunhd.blog.51cto.com/113473/20629

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号