这是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());
}这是servlet里的post方法:
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();
}问题是现在怎么连接不上服务器啊,小弟新手,呵呵,拜求大侠们能够指点下。感激不尽、感激不尽
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());
}这是servlet里的post方法:
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();
}问题是现在怎么连接不上服务器啊,小弟新手,呵呵,拜求大侠们能够指点下。感激不尽、感激不尽
另外,提高结帖率有助于你连上servlet!哈哈