Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

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

bangar50
Level 7
Level 7

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
MohitKumarK
Correct answer by
Level 4
Level 4

Hi @bangar50 ,

 

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
MohitKumarK
Correct answer by
Level 4
Level 4

Hi @bangar50 ,

 

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