java servlet中的运行时错误

时间:2010-03-16 16:20:57

标签: java exception servlets

项目的构建是成功的,但当我去网址时,我得到以下错误报告:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Error instantiating servlet class example.servlet.ScrapingServlet
 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
 org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
 java.lang.Thread.run(Thread.java:619)

root cause

java.lang.NoClassDefFoundError: org/apache/http/impl/client/DefaultHttpClient
 java.lang.Class.getDeclaredConstructors0(Native Method)
 java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
 java.lang.Class.getConstructor0(Class.java:2699)
 java.lang.Class.newInstance0(Class.java:326)
 java.lang.Class.newInstance(Class.java:308)
 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
 org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
 java.lang.Thread.run(Thread.java:619)

root cause

java.lang.ClassNotFoundException: org.apache.http.impl.client.DefaultHttpClient
 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
 java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
 java.lang.Class.getDeclaredConstructors0(Native Method)
 java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
 java.lang.Class.getConstructor0(Class.java:2699)
 java.lang.Class.newInstance0(Class.java:326)
 java.lang.Class.newInstance(Class.java:308)
 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
 org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
 java.lang.Thread.run(Thread.java:619)

>note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.
Apache Tomcat/6.0.14

那是因为我在代码中添加了这个简单的行: DefaultHttpClient httpclient = new DefaultHttpClient();

我做错了什么?

2 个答案:

答案 0 :(得分:2)

在堆栈跟踪中要注意的关键是 java.lang.ClassNotFoundException:org.apache.http.impl.client.DefaultHttpClient

它告诉你它在类路径中找不到org.apache.http.impl.client.DefaultHttpClient。解决这个问题,生活会变得更好。

答案 1 :(得分:1)

您需要将HttpClient库放在/WEB-INF/lib中,这是默认运行时类路径的一部分。