Rendering Content - Default GET Servlets
Default GET and HEAD servlets¶
Sling provides a number of default GET and HEAD servlets, in the
This provides useful functionality out of the box: JSON rendering of content for example, usually does not require custom code.
This page provides an overview of these default servlets.
Currently, only the
DefaultGetServlet has configuration parameters. Those are found at
/system/console/configMgr/org.apache.sling.servlets.get.DefaultGetServlet on a standard Sling setup,
and should be self-explaining. One common use is to disable some of the default renderings listed below,
as they might not be useful or desired on production systems.
Default JSON rendering¶
Adding a .json extension to a request triggers the default Sling GET servlet in JSON mode, unless a more specific servlet or script is provided for the current resource.
This servlet currently supports the following selectors:
.tidycauses the JSON output to be formatted
.harraycauses child nodes to be output as arrays instead of objects, to preserve their order (requires
- A numeric value or
.infinityas the last selector selects the desired recursion level
Note that the number of elements is limited by a configurable value, see the
DefaultGetServlet configuration for more info.
Default HTML rendering¶
In a similar way, adding a
.html extension to a request triggers the default Sling GET servlet in HTML
mode. That rendering just dumps the current node values in a readable way, but it's only really useful
Default text rendering¶
A basic text rendering is also provided if the request has a
.txt extension, unless more specific servlets
or scripts are provided.
Default XML rendering¶
.xml extension triggers the default XML rendering, once again unless a more specific script or
servlet is registered for the current resource.
That XML rendering currently uses the JCR "document view" export functionality directly, so it only supports rendering resources that are backed by JCR nodes.
Whenever the request carries the extension
.res or no extension at all, the resource's input stream is spooled to the servlet response (leveraging
Resource.adaptTo(InputStream.class)). This servlet supports conditional requests (RFC 7232) evaluating the resource's modification date from
Resource.getResourceMetadata().getModificationTime() and range requests (RFC 7233).
RedirectServlet handles the
sling:redirect resource type, using the
sling:target property of the
resource to define the redirect target, and the
sling:status property to define the HTTP status to use (default is 302).
This is not to be confused with the
sling:redirect property used under
/etc/map, which is described in
Mappings for Resource Resolution
SlingInfoServlet provides info on the current JCR session, for requests that map to JCR nodes.
It is available at
/system/sling/info.sessionInfo by default, and supports