This article is about integrating GWT with Grails. Here, GWT makes request to the Grails server which then returns a JSON object back to the GWT client.
Here’s a way to do post using GWT
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "http://localhost:9098/json/json/jsontest"); rb.setHeader("Content-Type", "application/x-www-form-urlencoded"); try { rb.sendRequest("jsontext="+hellothere.toString(), new DateCallbackHandler()); } catch (RequestException e) { Window.alert(e.toString()); }
By the way, its calling a controller of a grails project.
Here’s how it handles it
def jsontest = { String _json = (params.jsontext)? params.jsontext:'{"JSON":"text"}' JSONObject obj = new JSONObject(_json) render obj.getString("JSON") }
Edit:
Mary, you should be able to find that info somewhere on the web. Essentially, you create a RequestBuilder, send a request using
sendRequest(java.lang.String requestData, RequestCallback callback)
callback should be a class that inherits RequestCallback interface. Now RequestCallback has a method
onResponseReceived(Request request, Response response)
that you should implement, and Response has some methods like getText() that you can use.
Cheers