tags:

views:

216

answers:

3

I have a JSP file, create.jsp, which receives a POST request from an Ext grid containing a data parameter. Firebug displays a POST like this:

{"data":{"a":"","b":"","c":""}}

When I try to retrieve the data from the request object in create.jsp using this method,

request.getParameter("data");

it returns null. In fact the request object contains no parameters or attributes.

I've tested create.jsp with a POST that contains xaction:read and then the request.getParameter("xaction") returns "read", as expected.

A: 

It seems that data has more than one value, so try:

request.getParameterValues("data");
Bozho
That unfortunately returns `null`.
ViralShah
loop through request.getParameterNames to see what is coming
Bozho
request.getParameterNames was empty.
ViralShah
'data' is in the http body, not passed as a request parameter.
Jonathan Julian
A: 

Ended up using the request.getReader() method to parse the request manually.

ViralShah
no, if the request is formed properly as a POST request (and not multipart, for example), then getParameter should be OK
Bozho
+2  A: 

That's a JSON string. Is it really been sent as request parameter? I.e.

data={"data":{"a":"","b":"","c":""}}

Those things are usually sent "plain vanilla" as request body which you need to process by HttpServletRequest#getInputStream() or HttpServletRequest#getReader().

Update: sorry, didn't see that you already figured it out. I had this topic apparently open for too long in a browser tab. But indeed, you need to parse the request body yourself whenever the request is not been sent by a "normal" HTML form. Please keep the character encodings in mind else you will go in trouble.

BalusC