【发布时间】:2015-06-22 21:03:04
【问题描述】:
我使用 HttpPost 将保存在数据库中的对象发送到 HttpServlet。但是在我将它保存到服务器端之后,我需要使用它对应的 id。那我该怎么做呢?
Gson gson = GsonFactory.getInstance();
String json1;
String url;
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
url = this.url + "/saveMyOrder";
nameValuePairs.add(new BasicNameValuePair("process", "save"));
Order object = new Order();
object.setName("Order");
object.setTime(new Date());
json1 = gson.toJson(object);
nameValuePairs.add(new BasicNameValuePair("json", json1));
HttpPost httpPost = new HttpPost(url);
try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
HttpResponse response = HttpOperations.httpClient.execute(httpPost);
if (response.getStatusLine().getStatusCode() == 200) {
Toast.makeText(getApplicationContext(), "Success ... ",
Toast.LENGTH_LONG).show();
finish();
} else {
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this)
.setMessage("ERROR!").setCancelable(true);
dlgAlert.show();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
我试着把我的代码转换成英文,所以如果你有什么不明白的地方,尽管问。
【问题讨论】:
标签: java android servlets callback http-post