关于HttpClient的
PostMethod method = new PostMethod("http://202.106.139.25/HBE/servlet/tdplogicbookingcontroller");一写到这一句的时候就出现java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
 org.apache.commons.httpclient.HttpMethodBase.<init>(Unknown Source)
 org.apache.commons.httpclient.methods.ExpectContinueMethod.<init>(Unknown Source)
 org.apache.commons.httpclient.methods.EntityEnclosingMethod.<init>(Unknown Source)
 org.apache.commons.httpclient.methods.PostMethod.<init>(Unknown Source)
 net.action.jcclass.postinformation(jcclass.java:77)
 org.apache.jsp.news_jsp._jspService(news_jsp.java:71)
 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:80

解决方案 »

  1.   

    package net.action;
    import java.util.*;
    import java.sql.*;
    import java.io.*;
    import java.util.ResourceBundle;
    import java.text.*;
    import java.io.IOException;
    import org.apache.commons.httpclient.*;
    import org.apache.commons.httpclient.methods.GetMethod;
    import org.apache.commons.httpclient.params.HttpMethodParams;
    import org.apache.commons.httpclient.methods.PostMethod;
    public class jcclass
    {
    public static ResourceBundle bundle=ResourceBundle.getBundle("tis");
    public static String url=bundle.getString("conn");
    Connection con=null;
    Statement stmt=null;
    public jcclass(){
         try{ Class.forName("org.gjt.mm.mysql.Driver").newInstance();
              }catch(Exception e){}
         try{
                con= DriverManager.getConnection(url);
                stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
              }catch(SQLException e){}
            }
    /*提交xml*/
             public ArrayList postinformation(int temp){
             ArrayList newsList = new ArrayList();
     String req = "<OTRequest>"+
     "<TransactionName>HotelSearch</TransactionName>"+
     "<Header>"+
     "<SessionID>1111111111</SessionID>"+
     "<Invoker>HBE</Invoker>"+
     "</Header>"+
     "<IdentityInfo>"+
     "<OfficeID>NATEST</OfficeID>"+
     "<UserID>aaa</UserID>"+
     "<Password></Password>"+
     "</IdentityInfo>"+
     "<ScrollingInfo>"+
     "<DisplayReq>30</DisplayReq>"+
     "<PageItems>10</PageItems>"+
     "<PageNo>1</PageNo>"+
     "</ScrollingInfo>"+
     "<SearchConditions>"+
     "<GDS></GDS>"+
     "<CheckInDate>20060428</CheckInDate>"+
     "<CheckOutDate>20060429</CheckOutDate>"+
     "<PropertyDetail>"+
     "<CityCode>PEK</CityCode>"+
     "<Supplier></Supplier>"+
     "<PropertyName>王府</PropertyName>"+
     //"<PropertyName/>"+
    "<Transportation/>"+
    "<PorName/>"+
    "<AreaCode/>"+
    "<RankCode/>"+
    "</PropertyDetail>"+
    "<RateDetail>"+
    "<PaymentType/>"+
    "<Currency></Currency>"+
    "<RateMin></RateMin>"+
    "<RateMax></RateMax>"+
    "<RateCode/>"+
    "</RateDetail>"+
    "<RoomDetail></RoomDetail>"+
    "</SearchConditions>"+
    "</OTRequest>";
    System.out.println(req);
    HttpClient client = new HttpClient();
    PostMethod method = new PostMethod("http://202.106.139.25/HBE/servlet/tdplogicbookingcontroller");
    method.setParameter("request",req);
    DefaultMethodRetryHandler retryhandler = new DefaultMethodRetryHandler();
    retryhandler.setRequestSentRetryEnabled(false);
    retryhandler.setRetryCount(1);
    method.setMethodRetryHandler(retryhandler);
            try {            client.executeMethod(method);
                InputStream is = method.getResponseBodyAsStream();            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"GB2312"));
                StringBuffer s = new StringBuffer();
                String tmp;
                while((tmp=reader.readLine())!=null) {
                   s.append(tmp);
                }
                System.out.println(s.toString());
                Map map = new HashMap();
                map.put("input",s.toString());
                newsList.add(map);
                return newsList;
              }
              catch (Exception e) {
                e.printStackTrace();
         }
                return newsList;
            }
    /*提交xml*/
    }
      

  2.   

    org/apache/commons/codec/DecoderException,该包是否已添加到工程中?找不到DecoderException类。
      

  3.   

    PostMethod method = new PostMethod
    改为
    PostMethod method = new PostMethod();
      

  4.   

    压根就没有org/apache/commons/codec/DecoderException这个包的。
    PostMethod method = new PostMethod();这样改的确会来,但那网址在哪里写呢?
      

  5.   

    http://202.106.139.25/HBE/servlet/tdplogicbookingcontroller
    这个这个
    还有一些参数,就在上面的reg
      

  6.   

    我现在把代码写在jsp文件里了
    就六句话        HttpClient client = new HttpClient();  
            HttpMethod method = new GetMethod("http://127.0.0.1:8080/1.jsp"); 
            client.executeMethod(method); 
            System.out.println(method.getStatusLine()); 
            System.out.println(method.getResponseBodyAsString()); 
            method.releaseConnection(); 但是出来的东西是
    java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
    org.apache.commons.httpclient.HttpMethodBase.<init>(Unknown Source)
    org.apache.commons.httpclient.methods.GetMethod.<init>(Unknown Source)
    org.apache.jsp._3_jsp._jspService(_3_jsp.java:87)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      

  7.   

    应该是你没有把包commons加到工程的classpath里面
    如果在jsp里面要加入到web服务器的lib路径里面
      

  8.   

    java.lang.NoClassDefFoundError
    兄弟,以后看到这个直接看看是不是没有支持包.没跑的.
    另外,apache/commons系列的东西应该抽时间了解个大概