![BlogImage.jpg](https://t4.ftcdn.net/jpg/03/11/48/07/240_F_311480720_IO1D0LoicprrsD7GCew5zJKjsgUhGrAP.jpg)
Abstract
In Adobe Experience Manager (AEM), a Sling servlet can be used for handling some RESTful request-responses ajax call. It is written in Java programming language and it can be registered as OSGi (Open Services Gateway Initiative) services. In order to trigger the script, there are two ways to register it: 1. By Path or 2. By resourcesTypes and I will explain in details below:
1. Register by Path
Say for example, you want to do a form POST request to the path /bin/payment from client side to the sling servlet class, you may use the annotation below:
@SlingServlet {
metatype = true,
methods = { "POST" },
paths = "/bin/payment"
}
public class YourServlet extends SlingSafeMethodsServlet {
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throw ServletException {
// do your work here
}
}
Then when there is a POST request to the http://localhost:4502/bin/payment, the above servlet would be trigger and the doPost method is invoked.
The prerequisites is that you have the local AEM up and running at the port 4502 and installed the bundle module via the maven bundle plugin. You may check the bundle is installed by navigating to the http://localhost:4502/system/console/bundles. If not, you may also manually upload the jar to install.
Read Full Blog
Q&A
Please use this thread to ask the related questions.
Kautuk Sahni