我需要做一个定时登陆网页获取数据的功能。
其中登陆网站获取数据功能目前已完成(使用httpclient),测试正常。
但是我用定时器调用就出现报错,报错如下:
<main> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3768)
<ERROR> Exception sending context initialized event to listener instance of class com.zbht.servlet.SystemStartup
java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpMethod
at com.zbht.servlet.SystemStartup.contextInitialized(SystemStartup.java:75)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:448)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.HttpMethod
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1362)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1208)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
... 16 more
private Timer normTimer;
public void contextInitialized(ServletContextEvent arg0) {
normTimer = new Timer("lize", true);
normTimer.schedule(new FormLogin(),0,60*5*1000);
}
public void contextDestroyed(ServletContextEvent arg0) {
normTimer.cancel();
}
经过断点调试,发现错误在normTimer.schedule(new FormLogin(),0,60*5*1000);
public class FormLogin extends TimerTask{
private static boolean isRunning = false;