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

 

March 9, 2022

Looks like your servlet is not available in the instance at first place.

3581 TIMER_END{285,ResourceResolution} URI=/bin/my/login resolves to Resource=NonExistingResource, path=/bin/my/login
3597 LOG Resource Path Info: SlingRequestPathInfo: path='/bin/my/login', selectorString='null', extension='null', suffix='null'
3598 TIMER_START{ServletResolution}
3605 TIMER_START{resolveServlet(/bin/my/login)}
5260 LOG {0}: no servlet found

 Cross check the deployment and see if you are able to see the servlet in 

http://localhost:4502/system/console/components and is active

or

http://localhost:4502/system/console/servletresolver Enter the servlet path and choose the method to be POST and see if it resolves to your servlet. 


 

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

what does that mean 🙂 😅

 

 

Flores-Lucas
June 20, 2023

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