apache http客户端中的异常

时间:2013-02-26 18:57:44

标签: java

我正在使用eclipse ide并且当我运行我的程序时一切正常但是当我在服务器上运行相同的程序时它会给我这个例外,我已经把我的所有远程文件以及我的lib文件夹中,请帮助我要简短地解决这个问题。

java.lang.ClassNotFoundException: org.apache.http.HttpRequest
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2836)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1160)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1668)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
    at org.controller.KeyRank.doPost(KeyRank.java:41)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

这是我的代码:

   public String readGoogle(String keyword, int page) {
        HttpClient client = new DefaultHttpClient();  

        // Create a method instance
        keyword = keyword.trim();
        keyword = keyword.replaceAll(" ", "+");

        String url = "http://www.google.com/search?q="+keyword+"&start="+page+"&btnG=Google+Search&aq=f&oq=";
        String responseBody = "";
        HttpGet method = new HttpGet(url);  

        //Provide custom retry handler is necessary  
        //:OC:method.getParams().setParameter(HttpConnectionParams.RETRY_HANDLER, new DefaultHttpRequestRetryHandler(3, false));  


        try{  
        //execute the method  


            System.out.println("executing request " + method.getURI());  

            // Create a response handler  
            ResponseHandler responseHandler = new BasicResponseHandler();  
            responseBody = client.execute(method, responseHandler);  
            System.out.println("----------------------------------------");  
            System.out.println(responseBody);  
            System.out.println("----------------------------------------");  



            } catch (HTTPException e) {  

                    System.err.println("Fatal protocol violation: " + e.getMessage());  
                    e.printStackTrace();  

                } catch (IOException e) {  

                    System.err.println("Fatal transport error: " + e.getMessage());  
                    e.printStackTrace();  
                } finally {  

                    //release the connection  
              method.releaseConnection();  

        }
        return responseBody;

    }

2 个答案:

答案 0 :(得分:2)

将Http核心jar添加到您的构建路径,从此URL找到所需的jar。 http://www.java2s.com/Code/Jar/h/Downloadhttpcorejar.htm

部署jar然后编译,你的错误将被解决。

答案 1 :(得分:1)

如果没有您的classpath configuration以及您正在部署应用程序的Web服务器的知识,那么要提供帮助并不容易,但从外观上看,您似乎错过了HttpCore jar部署环境。

在那个罐子里找到了丢失的类。