How to call a servlet from react component | Community
Skip to main content
Level 2
March 8, 2022

How to call a servlet from react component

  • March 8, 2022
  • 3 replies
  • 8111 views

 

 

Hi,

do you have any tutorial on how to create servlet and call it from react?

 

I did this, I create one servlet like that

and I call it in react like that

 

and I got this error in console

 

 

How can I solve it?

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

Siva_Sogalapalli
Community Advisor
Community Advisor
March 8, 2022

I hope you're trying to call the servlet from AEM itself, did you try by removing localhost:4502 and just use something like post('/bin/login', fromData) and see how it works.

 

 

 

Level 2
March 8, 2022
Anmol_Bhardwaj
Community Advisor
Community Advisor
March 8, 2022

Can you try this and see if it works:

If your requests are getting blocked, this should fix it.

 

- Please check if you have implemented SlingHttpSafeServlet or AllMethodServlet in your servlet.

- Try to call the same servlet through Postman and see if it is working fine

 

Level 2
March 8, 2022

@anmol_bhardwaj 

 

I tried that, does not works

 

I have this as filter

 

Vijayalakshmi_S
Level 10
March 9, 2022

 

I did not found it in http://localhost:4502/system/console/components

what does that mean 🙂 😅

 

 


This means your bundle (that contains the servlet code) is not deployed to the AEM instance. 

How are you deploying your code ?

 

Flores-Lucas
June 20, 2023

Just dealing with the same error here, I came around this article that may be helpful: