我查出数据库的数据 推送给安卓解析, 由于安卓的接口没有做好,我自己做了个
servlst 进行解析。但是不知道怎么拿值!
这是 推送数据的方法!
public static String doPost(String url,JSONArray json){
String result=null;
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
JSONObject response = null;
try {
StringEntity s = new StringEntity(json.toString());
s.setContentEncoding("UTF-8");
s.setContentType("application/json");//发送json数据需要设置contentType
post.setEntity(s);
HttpResponse res = client.execute(post);
if(res.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
HttpEntity entity = res.getEntity();
result = EntityUtils.toString(res.getEntity());// 返回json格式:
// response = JSONObject.fromObject(result);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return result;
}
一下是 servlst 解析的方法
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("POST请求方式");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
//String param=request.getParameter(""); //接收数据
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST 200 method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}