Expand my Community achievements bar.

SOLVED

for doPost servlet, SlingHttpServletRequest getting empty

Avatar

Level 4

From Dam, I have uploaded a html and js files, For that dam js, I am posting the formdata to servelt using ajax call, the request will entered into the dopost method but request parameter are getting empty.

1 Accepted Solution

Avatar

Correct answer by
Level 4

Hello everyone.

Thank you for taking the time to respond. I noticed an unusual behaviour: when we print in the logger.info, we get an empty text, while the same data is populating in the payload.

 Quite strange behaviour

 

 

 

View solution in original post

5 Replies

Avatar

Community Advisor

@kbitra1998 can you share code snippet using to read post request data in servlet?

check this out, if it solves your problem

javascript - Servlet in AEM, body in POST request is lost - Stack Overflow

 

Avatar

Correct answer by
Level 4

Hello everyone.

Thank you for taking the time to respond. I noticed an unusual behaviour: when we print in the logger.info, we get an empty text, while the same data is populating in the payload.

 Quite strange behaviour

 

 

 

Avatar

Community Advisor

@kbitra1998 You should be able to get value in logger.info as well, not sure how are you passing parameters to logger. Did you get a chance to print the same variables/parameters using system.out.println(for testing purpose)?

Avatar

Level 4

The mistake I have made is logger.info ("AEM" + parameter) it is printing in the logs. However, if I put logger.info("AEM", parameter) it is not printing in the logs.

Avatar

Level 6

Check if formdata that you are passing are properly populated in your javascript. You can print that in console and check.

Sharing the code that works for me:

var formData = new FormData($("#formId")[0]);

Make sure in your form you have all your inputs set with name and value, name matching with the request parameter name that you fetch in the servlet.