Hi,
I am sending a RPCRequest to the server as shown below. It works fine except when I add the the statement to setContentType to json as shown below. In this case the getParameter statement in the server returns null. I am trying to set up the servlet to accept json requests.
I am using SmartGWT Pro 5.0p.
Client side code:
Server code is a servlet:
In dev console, the request looks like this
I am sending a RPCRequest to the server as shown below. It works fine except when I add the the statement to setContentType to json as shown below. In this case the getParameter statement in the server returns null. I am trying to set up the servlet to accept json requests.
I am using SmartGWT Pro 5.0p.
Client side code:
Code:
HashMap<String, String> h = new HashMap<String, String>(); h.put("caller", "login"); h.put("uid", uid); h.put("password", password); RPCRequest req = new RPCRequest(); req.setParams(h); req.setActionURL(dataUrl); req.setContentType("application/json"); // works fine without this line of code RPCManager.sendRequest(req, new RPCCallback() { ... });
Code:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // getParameter returns null when contentType is set to 'json' in client request. // when contentType is not explicitly set (left as x-www-form-urlencoded) then getParameter call // returns value as expected String caller = request.getParameter("caller"); }
Code:
{ "actionURL":"http://127.0.0.1:8888/appname/sc/Login", "showPrompt":false, "transport":"xmlHttpRequest", "promptStyle":"cursor", "params":{ "caller":"login", "password":"passwd", "uid":"bc", "isc_tnum":0 }, "contentType":"application/json" }
Comment