A question about Sling servlets and resource types | Community
Skip to main content
LinearGradient
Level 6
October 16, 2015
Solved

A question about Sling servlets and resource types

  • October 16, 2015
  • 1 reply
  • 1801 views

Hi,

When a Sling servlet is defined using paths, similar to:

@SlingServlet(paths = "/bin/example", ...)

It is accessible via localhost:4502/bin/example.

When it is defined using resourceTypes, similar to:  

@SlingServlet(resourceTypes = "foo:example", ...)

Under what URL(s) will be accessible?

Also when does it make sense to define a servlet using resourceTypes rather than paths?

Thanks.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by PaulMcMahon

When a servlet is registered to a resourceType then the servlet is available at any URL matching the resource type. So for example if the node /content/foo/bar has a sling resource type of foo.example then the servlet would render for any request to that node in theory. Normally the resourceTypes property is combined with other restrictions - extension or selector or request method to narrow the scope of the servlet.

Normally you use the resourceTypes property when you are creating a servlet that renders content stored on a node, as opposed to servlets that are more service oriented which is what you normally see in the /bin areal.  

1 reply

PaulMcMahonAccepted solution
Level 8
October 16, 2015

When a servlet is registered to a resourceType then the servlet is available at any URL matching the resource type. So for example if the node /content/foo/bar has a sling resource type of foo.example then the servlet would render for any request to that node in theory. Normally the resourceTypes property is combined with other restrictions - extension or selector or request method to narrow the scope of the servlet.

Normally you use the resourceTypes property when you are creating a servlet that renders content stored on a node, as opposed to servlets that are more service oriented which is what you normally see in the /bin areal.