May 1, 2020
Estimated Post Reading Time ~

Sling Servlet definition Code Snippets

Sling Servlet annotations
Configurations methods, resourceTypes, selectors, extensions are IGNORED if paths is set.

Methods defaults to GET if not specified.


@SlingServlet(
        label = "Samples - Sling Servlet",
        description = "...",
        paths = {"/services/all-sample"},
        methods = {"GET", "POST"}, 
        resourceTypes = {}, 
        selectors = {"print.a4"},
        extensions = {"html", "htm"}  
)

Safe Methods Servlet (GET, HEAD)
public class SampleServlet extends SlingSafeMethodsServlet implements OptingServlet {
    
    @Override
    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
            throws ServletException, IOException { ... }
 
}

All Methods Servlet (GET, HEAD, POST, PUT, DELETE)
public class SampleServlet extends SlingAllMethodsServlet implements OptingServlet {

    @Override
    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
            throws ServletException, IOException { ... }

}


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.