How to find out an resourceType in aem | Community
Skip to main content
Level 3
December 11, 2023
Solved

How to find out an resourceType in aem

  • December 11, 2023
  • 3 replies
  • 2289 views

I have a servlet that has resource type = sling/servlet/default. How can I find a resource inside my project or how can i create a resource/component with this resourcetype

Best answer by Sudheer_Sundalam

@vineetham123 ,

In this case, replace the value of the CommonConstants.SLING_SERVLET_DEFAULT with the resource type of the page you create. You can find the resource type of any page by going into http://localhost:4502/crx/de/index.jsp and search with the page path you created. Copy the value of "sling:resourceType" property of the page you created and update your Servlet with that value.

Hope this helps!

 

 

3 replies

arunpatidar
Community Advisor
Community Advisor
December 11, 2023

Hi @vineetham123 
Could you please explain use case in details?

Arun Patidar
aanchal-sikka
Community Advisor
Community Advisor
December 11, 2023

Hello @vineetham123 

 

Please refer to this documentation https://sling.apache.org/documentation/the-sling-engine/servlets.html

 

A default Servlet is selected if no servlet (or script) for the current resource type can be found. To make the provisioning of a default Servlet as versatile as provisioning per resource type Servlets (or scripts), the default Servlet is selected with just a special resource type sling/servlet/default.

 

As you would notice, its not a real resource type but a fallback. A way to define a Default Servlet. So, we don't create components using this resource type. It is just used to create Default Servlets

 

Aanchal Sikka
Level 3
December 11, 2023

Thanks for the response @aanchal-sikka . See the below code

@Component(service = {Servlet.class})
@SlingServletResourceTypes(
resourceTypes = {
CommonConstants.SLING_SERVLET_DEFAULT},
methods = HttpConstants.METHOD_GET,
selectors = {"destination"},
extensions = "json")
@SlingServletName(servletName = "Sample Vegetable Shop Servlet")
@ServiceDescription("Santhosh Vegetables - Veggie Servlet")
public class DestinationServlet extends SlingSafeMethodsServlet {
}

 

How can I access this in debug mode, (suppose that I know how to debug in aem) ,and suppose that I dont have enough packages in my local machine. I need to create some pages and fire a url that will eventually hit this servlet 

Sudheer_Sundalam
Community Advisor
Sudheer_SundalamCommunity AdvisorAccepted solution
Community Advisor
December 11, 2023

@vineetham123 ,

In this case, replace the value of the CommonConstants.SLING_SERVLET_DEFAULT with the resource type of the page you create. You can find the resource type of any page by going into http://localhost:4502/crx/de/index.jsp and search with the page path you created. Copy the value of "sling:resourceType" property of the page you created and update your Servlet with that value.

Hope this helps!

 

 

kautuk_sahni
Community Manager
Community Manager
January 2, 2024

@vineetham123 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni