android客户端与服务器servlet通信的一个问题,求解惑。。。
这是android里的程序:
TextView t=(TextView)Select.this.findViewById(R.id.textView00); String strResult; String uriAPI="http://10.255.153.46:8080/GetInfor/servlet"; HttpPost httpPostRequest=new HttpPost(uriAPI); List<NameValuePair> httpParams = new ArrayList<NameValuePair>(); httpParams.add((NameValuePair) new BasicNameValuePair("information", s)); //设置post参数 try { httpPostRequest.setEntity(new UrlEncodedFormEntity(httpParams,HTTP.UTF_8)); HttpResponse httpResponse = new DefaultHttpClient().execute(httpPostRequest); Log.d("Infor", "post:"+httpResponse.getStatusLine().getStatusCode()); if(httpResponse.getStatusLine().getStatusCode()==200){ //连接成功 String result = EntityUtils.toString(httpResponse.getEntity()); //获得资源 result = result.replaceAll("\r\n|\n\r|\r|\n", ""); t.setText(result); } } catch (Exception e) { //捕获并打印异常 //获得EditText对象 t.setText("连接出错:"+e.getMessage()); }public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.print("ziyanguang:"+out); out.flush(); out.close(); }