济南市建设执业资格注册中心网站,以百度云做网站空间,小型网吧网络设计方案,做网站的公司搞什么活动其他的JSP文章: 在JSP中使用Bean自动属性填充机制 JSP列出服务器环境变量 JSP的errorPage指令异常转向错误页的实现机制及应用 Jsp利用404错误页进行URL重写 有的时候需要在JSP运行时#xff0c;定时执行一些程序#xff0c;比如说统计流量、更新缓存数据等#xff0c;通常要…其他的JSP文章: 在JSP中使用Bean自动属性填充机制 JSP列出服务器环境变量 JSP的errorPage指令异常转向错误页的实现机制及应用 Jsp利用404错误页进行URL重写 有的时候需要在JSP运行时定时执行一些程序比如说统计流量、更新缓存数据等通常要使用Listener和Timer下面就是一个简单应用目的就是时刻检查程序是否正在执行当中。 首先创建一个TimerTask public class LogTask extends TimerTask { Override public void run() { // TODO Auto-generated method stub SimpleDateFormat sdf new SimpleDateFormat(yyyy-MM-dd HH:mm:ss); System.out.println( sdf.format(new Date()) --this programe is running!); }} 接着创建监听程序 public class LogListener implements ServletContextListener { private Timer timer null; Override public void contextDestroyed(ServletContextEvent arg0) { // TODO Auto-generated method stub if (timer ! null) { timer.cancel(); } } Override public void contextInitialized(ServletContextEvent arg0) { // TODO Auto-generated method stub if (timer null) { timer new Timer(); timer.schedule(new LogTask(), new Date(), 1000); } }} 在web.xml配置listener listener-classorg.heroking.web.LogListener/listener-class /listener 转载于:https://www.cnblogs.com/ctou45/archive/2013/02/01/2889677.html