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
Solved! Go to Solution.
Views
Replies
Total Likes
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!
Hi @vineetham123
Could you please explain use case in details?
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
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
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!
This is very frequently used with assets. Example:
http://localhost:4502/content/dam/wknd/en/site/not-found.jpg.destination.json
Even this would work
http://localhost:4502/content/wknd/language-master.destination.json will call your servlet, due to selector and extension
http://localhost:4502/content/wknd/language-masters.model.json will return results from OOTB Page model
In a way, the servlet is no longer bound to a resource type... Rather becomes available for generic use
@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.
Views
Replies
Total Likes
Views
Likes
Replies