Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Diving into the World of Sling Servlets in Adobe Experience Manager | AEM Community Blog Seeding

Avatar

Administrator

BlogImage.jpg

Diving into the World of Sling Servlets in Adobe Experience Manager by Techzette

Abstract

In this post, we will go over the different annotations that are used in a Sling Servlet, and provide a sample code example to help illustrate their usage.

A Sling Servlet is a type of Java servlet that is used to handle HTTP requests in AEM. These servlets are typically used to handle the creation and retrieval of content, as well as to perform other tasks related to managing content in AEM. Sling Servlets can be created using the Sling API

Here is a sample Sling Servlet that illustrates the use of different annotations:

@SlingServlet(paths="/bin/example", methods="GET", selectors="data")
public class ExampleServlet extends SlingSafeMethodsServlet {

@SlingObject
private Resource resource;

@ValueMapValue
@Named("jcr:title")
private String title;

@Properties
private ValueMap properties;

@Modify
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) {
//do something with resource, title, properties
}
}
In this example, the @SlingServlet annotation is used to mark the class as a Sling Servlet, and to specify that the servlet will handle GET requests at the path “/bin/example” with the selector “data”.

The @SlingObject annotation is used to inject the current Resource object into the servlet, which can be used to retrieve content or other data that is relevant to the request. The @ValueMapValue and @Named annotation is used to retrieve a value from the resource’s ValueMap and the property name is ‘jcr:title’.

Read Full Blog

Diving into the World of Sling Servlets in Adobe Experience Manager

Q&A

Please use this thread to ask the related questions.



Kautuk Sahni
0 Replies