Android receives servlet return value

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.