http - sending data in Post Method from Android Client to Java Servlet -


i implement client server code java android. problem couldn't able connect servlet. problem? here code:

android code: ....

httpclient client=new defaulthttpclient(); httppost getmethod=new httppost("http://" + server + "/restaurantserver/login");  try {     // add data arraylist<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(3); namevaluepairs.add(new basicnamevaluepair("mode", "login")); namevaluepairs.add(new basicnamevaluepair("username",txtusername.gettext().tostring() ));     namevaluepairs.add(new basicnamevaluepair("password",txtpassword.gettext().tostring() ));      getmethod.setentity(new urlencodedformentity(namevaluepairs));     client.execute(getmethod);  } catch (clientprotocolexception e) {     e.printstacktrace(); } catch (ioexception e) {     e.printstacktrace(); } 

and server side:

protected void processrequest(httpservletrequest request, httpservletresponse response)         throws servletexception, ioexception {     response.setcontenttype("text/html;charset=utf-8");     printwriter out = response.getwriter();      try {         string mode=request.getparameter("mode");         if ("login".equals(mode)) {             string username= request.getparameter("username");             string password= request.getparameter("password");             system.out.println("post method: "+username + "! pass :"+password);             user = new user(password,username);             if (userdao.authenticate(user)==true)                 out.write("accept".tostring());             else                 out.write("wrong".tostring());         } else if ("register".equals(mode)) {             string username= request.getparameter("username");             string password= request.getparameter("password");             string name= request.getparameter("name");             string email= request.getparameter("email");             string address= request.getparameter("address");             string phonenumber= request.getparameter("phonenumber");             system.out.println("reg mod: "+username + "! pass :"+password);             user = new user(username,password,name,email,address, phonenumber);              if (userdao.adduser(user) == true)                 out.write("added");             else                 out.write("notadded");         }     } catch (exception ex) {         system.out.println("problem in message reading");     } } 

change method name processrequest() dopost() , check mapping in web.xml.may servlet , url mapping not correct.send web.xml , name of servlet.


Comments