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

How to call a servlet from react component

  • March 8, 2022
  • 3 replies
  • 8090 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.

 

 

 

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

 

March 8, 2022

@anmol_bhardwaj 

 

I tried that, does not works

 

I have this as filter

 

Vijayalakshmi_S
March 9, 2022

using command 

 

mvn clean install -PautoInstallPackage


Since it is your local instance, delete the bundle manually from this path - /apps/yourproject/install/yourproject.core-0.0.1-SNAPSHOT.jar in CRXDE and then trigger the deployment again. 

(Provided core module is enabled and bundle is getting created successfully as part of the build process)

Flores-Lucas
June 20, 2023

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