Expand my Community achievements bar.

SOLVED

Json object giving null value after sending json array to the sling Servlet

Avatar

Community Advisor

Hi All,

         I have created Sling Servlet and  I wanted to pass json raw data to the Slingservlet but it is showing null values.

IMG_20211102_075919.jpg

IMG_20211102_075836.jpgplease check anything that I missed.

1 Accepted Solution

Avatar

Correct answer by
Level 4

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!

 

 

View solution in original post

2 Replies

Avatar

Correct answer by
Level 4

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!