Hi
Please have a look at this community article for your help:-
Link:- https://hashimkhan.in/aem-adobecq5-code-templates/servlets/
//
There is reason why resourceType is much more preferential and suggested for writing SlingServlets. Below are the few reasons I could think of:
- While defining a path , you must be specific what all paths are allowed to be used in the ServletResource OSGi service. If you define something randomly, your servlet might not be fucntional. Only a limited paths are allowed and the rest are blocked unless you open them up. This is resolved using resourceType.
- You may have also configure the dispatcher , if you use some random path for your servlet. This might be a potential security threat and a needless configuration.
- You might also have to specify the paths to your consumers for your servlet and any change in that path could have a serious affect. This might not be the case when you use resourceType
- the Sling Engine will take care of permissions for you. Users who cannot access a particular resource will not be able to invoke the servlet.
I hope this will be helpful to you.
Thanks and Regards
Kautuk Sahni
Kautuk Sahni