Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON Message post from GWT to Spring MVC Controller
    primarykey
    data
    text
    <p>I am trying to post a JSON message from GWT to a Controller in Spring MVC Framework. The spring controller is receiving request from GWT, but when I print out the request content length and request.toString(), it shows 0 for the content lenght and the output of the request.toString() does not have any content.</p> <p><strong>The following is my codes and output:</strong></p> <p>The following is my GWT code that perform the posting of JSON message :</p> <pre><code>@UiHandler("saveButton") void onClick(ClickEvent e) { UserAddJSO jso = (UserAddJSO)JavaScriptObject.createObject().cast(); jso.setFirstName("Alex"); jso.setLastName("Cheng"); RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, "addUser.aj"); builder.setHeader("Content-Type", "application/json"); builder.setRequestData(new JSONObject(jso).toString()); System.out.println("request data :"+builder.getRequestData()); try { builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { Window.alert("on error"); } public void onResponseReceived(Request request, Response response) { Window.alert("response received :"+response.getStatusCode()); Window.alert(response.getText()); } }); } catch (RequestException excp) { Window.alert("exception catched"); } } </code></pre> <p>from the above code you can see i have a print out on the request data, the json string is there.</p> <p>there following is my Spring controller:</p> <pre><code>@RequestMapping(value = "**/addUser.aj", method = RequestMethod.POST, produces = "application/json") @ResponseBody public List&lt;UserAddDTO&gt; getPostStocks(HttpServletRequest request, HttpServletResponse response) throws IOException { List&lt;UserAddDTO&gt; userDTO = new ArrayList&lt;UserAddDTO&gt;(); JSONObject jObj; jObj = new JSONObject(request.getParameterMap()); System.out.println(jObj.toString()); System.out.println("xxxxxxxxxxxxx "+request.toString()); System.out.println("content type :"+request.getContentType()); System.out.println("inside post method"); return userDTO; } </code></pre> <p>The following is the output from the above print out :</p> <pre><code>request data :{"firstName":"Alex", "lastName":"Cheng"} content type :application/json content length :0 inside post method {} xxxxxxxxxxxxx POST /addUser.aj HTTP/1.1 Accept: */* Referer: http://127.0.0.1:8888/AlliumApp.html?gwt.codesvr=127.0.0.1:9997 Accept-Language: en-us User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; Tablet PC 2.0; BRI/2) Accept-Encoding: gzip, deflate Host: 127.0.0.1:8888 Connection: Keep-Alive Content-Type: application/json Content-Length: 0 Cache-Control: no-cache </code></pre> <p>from the above output you can see the JSON message is there inside the request. But when it reached the controller the JSON message is not there anymore. So am i doing the right way for json message posting and receiving?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload