码迷,mamicode.com
首页 > 移动开发 > 详细

android接收servlet返回值

时间:2016-04-14 15:47:18      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String str = "你好-kobe";
        response.getOutputStream().write(str.getBytes("utf-8"));//如果不指定utf-8编码,以默认gbk编码传值,需要在android端处理
}
private void send2Server() {
        String path = "http://192.168.8.19:8080/LoginServlet";
        AsyncHttpClient client = new AsyncHttpClient();
        client.get(path, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, byte[] bytes) {
                try {
                    //接收Servlet传回的值
                    String str = new String(bytes,"utf-8");//默认是utf-8,可以不写
                    //String str = new String(bytes,"gbk");//如果服务器不指定utf-8,需要在客户端用gbk解
                    Log.i("log", str );
                    Toast.makeText(MainActivity.this, str, Toast.LENGTH_LONG).show();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                Log.i("log", "onFailure");
            }
        });
    }

 

android接收servlet返回值

标签:

原文地址:http://www.cnblogs.com/linson0116/p/5390958.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!