Send JSON-Object as POST in RequestBuilder
At client-side:
JSONArray devicedata=new JSONArray();
devicedata.set(0,"zero");
devicedata.set(1, "one");
devicedata.set(2, two);
try { String url=localhost:8080/requestsend/servlet;
RequestBuilder builder=new RequestBuilder(RequestBuilder.POST, url);
//adding the post data
builder.setRequestData(devicedata.toString());
builder.setCallback(new RequestCallback()
{ @Override public void onResponseReceived(Request request, Response response)
{ popup.setVisible(false); JSONValue value=JSONParser.parse(response.getText()); JSONObject jobj=value.isObject(); if(jobj.get("status").isString().stringValue().equalsIgnoreCase("success")) {
} @Override public void onError(Request request, Throwable exception)
{ Window.alert("Error occurred" + exception.getMessage()); } }); builder.send();
}catch(Exception e) { }
At Server Side:
String s=req.getReader().readLine(); JSONArray jarray=new JSONArray(s);
0 comments:
Post a Comment