Hi All,
I have created Sling Servlet and I wanted to pass json raw data to the Slingservlet but it is showing null values.
please check anything that I missed.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @Sanjay_Bangar ,
When doing a ajax call use something like below
var square = {};
square.length = 10;
square.width = 10;
$.ajax(
url: url,
data: JSON.stringify(square),
dataType: “json”
contentType: “application/json”,
);
while reading in servlet you can use like below:
String requestBody = request.getReader().lines().collect(Collectirs.joining());
you can use any Utils class to convert from string to json or java bean.
Thanks!
Try 2nd the solution in the below link: https://stackoverflow.com/questions/33896136/read-json-message-from-http-post-request-in-java
Hope this helps.
Thanks,
Kiran Vedantam
Hi @Sanjay_Bangar ,
When doing a ajax call use something like below
var square = {};
square.length = 10;
square.width = 10;
$.ajax(
url: url,
data: JSON.stringify(square),
dataType: “json”
contentType: “application/json”,
);
while reading in servlet you can use like below:
String requestBody = request.getReader().lines().collect(Collectirs.joining());
you can use any Utils class to convert from string to json or java bean.
Thanks!
Views
Likes
Replies