0

I work with java servlets and I want to receive Big json data from client.

my client code is

 url: "http://localhost:8080/JsonTest/setJson",
 type: "POST",
 dataType: 'json',
 contentType: 'application/json',
 data:{json:str},

my server code is

String json=request.getParameter("json");

but json variable is null

Can anybody help me?

javagc
  • 846
  • 1
  • 17
  • 37
  • The JSON will be written in the body. Use the `getInputStream` method of the `HttpServletRequest` to read the JSON from the request body. Then use a JSON parser to parse it. – Sotirios Delimanolis Nov 01 '13 at 12:38
  • example of what you want to do is here http://stackoverflow.com/questions/3831680/httpservletrequest-get-post-data – Zyga Nov 01 '13 at 12:43

1 Answers1

0

try JSON.stringify on the data:

url: "http://localhost:8080/JsonTest/setJson",
type: "POST",
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({json:str}),

or if str is already a json string:

url: "http://localhost:8080/JsonTest/setJson",
type: "POST",
dataType: 'json',
contentType: 'application/json',
data: str,
R. Oosterholt
  • 7,720
  • 2
  • 53
  • 77