protected void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException { String str = "Hello-kobe"; Response.getoutputstream (). Write (Str.getbytes ("Utf-8")), or//If you do not specify UTF-8 encoding, pass the value by default GBK encoding, need to process on the Android side}
Private voidSend2server () {String path="Http://192.168.8.19:8080/LoginServlet"; Asynchttpclient Client=Newasynchttpclient (); Client.Get(Path,NewAsynchttpresponsehandler () {@Override Public voidOnsuccess (intI, header[] headers,byte[] bytes) { Try { //receive values returned by ServletString str =NewString (Bytes,"Utf-8");//default is Utf-8, can not write//string str = new string (bytes, "GBK");//If the server does not specify UTF-8, the client needs to use the GBK solutionLOG.I ("Log", str); Toast.maketext (mainactivity. This, str, toast.length_long). Show (); } Catch(Exception e) {e.printstacktrace (); }} @Override Public voidOnFailure (intI, header[] headers,byte[] bytes, throwable throwable) {LOG.I ("Log","onfailure"); } }); }
Android receives servlet return value