Servlet call in AEM

202 Views Asked by At

I am just trying to execute a servlet in AEM which should be called when a component (whose sling:resourceType="harsh/components/content/mycomponent" ) is loaded on any page

I tried the same what I mentioned above but its not hitting the servlet.

1

There are 1 best solutions below

1
On

There is more than one way to map a resourceType to a servlet : it can be a Java class, a JSP page, etc.

The snippet below should work or you:

@Component(service = Servlet.class, property = {
        "sling.servlet.resourceTypes=harsh/components/content/mycomponent",
        "sling.servlet.methods=POST"
})
public class MyComponentServlet extends SlingAllMethodsServlet {
    @Override
    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
       // TODO
    }
}