java - JSONObject error in servlet -


i've created servlet class receiving string android client. class send string servlet class. using rest api receive correctly string, when create jsonobject, throws java.lang.classnotfoundexception: net.sf.json.jsonobject. here code implemented:

             protected void dopost(httpservletrequest request,                 httpservletresponse response) throws servletexception, ioexception {              printwriter out= response.getwriter();                  arraylist<string> arrivo;                 arraylist<string> preference=new arraylist<string>();                                     stringbuffer jb = new stringbuffer();                       string line = null;                       try {                         bufferedreader reader = request.getreader();                          while ((line = reader.readline()) != null)                           jb.append(line);                         preference.add(line);                         response(response,"ok");                         system.out.println(response);                       }     catch (exception e) { //report error                     }                        response(response,"no");                      try {                               string s=jb.tostring();                               arrivo=new arraylist<string>(arrays.aslist(s.split(",")));                        } catch (parseexception e) {                         throw                        new ioexception("error parsing json request string");                       }                      invio(arrivo);                              }           public void invio(arraylist<string> c){              string pref="";             string x=c.tostring();               stringbuilder sb = new stringbuilder();                string http = "http://mioserver:80808";                httpurlconnection urlconnection=null;               try {                   url url = new url(http);                   urlconnection = (httpurlconnection) url.openconnection();                 urlconnection.setdooutput(true);                   urlconnection.setrequestmethod("post");                   urlconnection.setusecaches(false);                   urlconnection.setconnecttimeout(10000);                   urlconnection.setreadtimeout(10000);                   urlconnection.setrequestproperty("content-type","application/json");                    //urlconnection.setrequestproperty("host","http://localhost:8080/w7turismoserver/servlet");                  urlconnection.connect();                  jsonobject object=new jsonobject();                 object.put("",pref);                outputstreamwriter out = new     outputstreamwriter(urlconnection.getoutputstream());                 out.write(object.tostring());                 system.out.println(object.tostring());                 out.close();                   int httpresult =urlconnection.getresponsecode();                   if(httpresult ==httpurlconnection.http_ok){                        bufferedreader br = new bufferedreader(new inputstreamreader(                           urlconnection.getinputstream(),"utf-8"));                       string line = null;                       while ((line = br.readline()) != null) {                           sb.append(line + "\n");                       }                       br.close();                         system.out.println(""+sb.tostring());                    }else{                           system.out.println(urlconnection.getresponsemessage());                   }                    } catch (malformedurlexception e) {                         e.printstacktrace();               }             catch (exception e) {                    e.printstacktrace();                   }                 } 

how can resolve problem? thank in advance.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -