这是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();
}问题是现在怎么连接不上服务器啊,小弟新手,呵呵,拜求大侠们能够指点下。感激不尽、感激不尽

解决方案 »

  1.   

    如果是真机,手机和电脑要在同一个网络(比如连上同一个wifi热点),手机才能访问tomcat。如果是模拟器,可能就是你的代码问题了。
    另外,提高结帖率有助于你连上servlet!哈哈
      

  2.   

    先看看你的客户端能不能进行正常的上网,再看看pc上能不能连上你的servlet。两者都可以了,再进行试验吧
      

  3.   

    问题已经解决是URI输入有误,呵呵,谢谢几位、、、
      

  4.   

    您好,请问是哪里的URL输入有误,我也遇到连接不上的问题了