Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

POST servlet not getting called.

Avatar

Level 4

Hi Experts,

 

I have a use case where i need to call the servlet which is registered with resourceType and method POST. Can someone please help me to suggest how can i achieve this. I have to call this on page load itself. Please suggest.

 

Thanks in advance.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

6.4
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@gargsahil099,

If you are testing from an HTTP Client such as postman, you will need to configure the "Apache Sling Referrer Filter" and "Adobe Granite CSRF Filter". Other than that, if your AEM page is making an HTTP Post request, it should be working as expected with only the "Apache Sling Referrer Filter" configured without the CSRF Filter. Check out this tutorial on how to make POST requests to your AEM instance - https://sourcedcode.com/how-to-make-simple-http-post-methods-in-aem-with-a-http-rest-client

What is the AEM Apache Sling Referrer Filter OSGI configuration? https://sourcedcode.com/in-aem-what-is-the-apache-sling-referrer-filter-osgi-configuration

 

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

@gargsahil099,

If you are testing from an HTTP Client such as postman, you will need to configure the "Apache Sling Referrer Filter" and "Adobe Granite CSRF Filter". Other than that, if your AEM page is making an HTTP Post request, it should be working as expected with only the "Apache Sling Referrer Filter" configured without the CSRF Filter. Check out this tutorial on how to make POST requests to your AEM instance - https://sourcedcode.com/how-to-make-simple-http-post-methods-in-aem-with-a-http-rest-client

What is the AEM Apache Sling Referrer Filter OSGI configuration? https://sourcedcode.com/in-aem-what-is-the-apache-sling-referrer-filter-osgi-configuration

 

Avatar

Level 4

Hi @BrianKasingli

 

I am looking for the solution where this servlet be called automatically on page load without any custom code as our doget method got called on sling:resourceType servlets.

 

Please suggest.

Avatar

Community Advisor

The best way to achieve this is with JavasScript. You can invoke JavasScript POST HTTP request when the page is loaded.

Before the closing </body> tag, you can add JavaScript either inline or with a client library of something that looks like this:

<html>
  <head></head>
  <body>
    ...
    <script type="text/javacript">
      $.ajax({
        type: "POST",
        url: "/content/my-site/ca/en/home",
        data: {},
        success: function(){}
      });
    </script>
  </body>
</html>