Expand my Community achievements bar.

Applications for the 2024-2025 Adobe Experience Manager Champion Program are open!
SOLVED

AEM Sling Sevlet Prefix annotaion

Avatar

Level 2

Hi, everyone

So I tried to use a prefix to limit my servlet, but when I checked the usage on doc, it requires a number that is in the resource path,[/app/ [lib]], but I believe it still works if I give a string, but I wonder what this prefix usage, cause I believe it is not the URL on my servlet, my servlet is based on resource type: cq: page and it has selector and extension, each of pages will response to this servlet, so ie. URL:/a/b/c.d.e, in this case, prefix is /a/b/? or I guess it is relative to the resources Type path?

So confused, any advice would be highly appreciated! thanks!  I'm trying to understand the purpose of this prefix and how it applies to my servlet configuration.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

The sling.servlet.prefix property in AEM is used to define the order of servlet resolution. It's not related to the URL or resource type of your servlet.

 

In Sling, all servlets and scripts are resources, and they're all stored under /apps or /libs. The sling.servlet.prefix property is used to define a search path for these resources. The default value is -1, which means that Sling will search in /apps and /libs for the servlet or script.

The sling.servlet.prefix property can be a number or a string. If it's a number, it's used as a priority. A higher number means a higher priority. If it's a string, it's used as a path. Sling will search for the servlet or script in this path.

 

https://sling.apache.org/documentation/the-sling-engine/servlets.html#:~:text=If%20the%20value%20of%....

 

sling.servlet.prefix

 

The prefix or numeric index to make relative paths absolute. If the value of this property is a number (int), it defines the index of the search path entries from the resource resolver to be used as the prefix. The defined search path is used as a prefix to mount this servlet. The number can be -1 which always points to the last search entry. If the specified value is higher than than the highest index of the search paths, the last entry is used. The index starts with 0. If the value of this property is a string and parseable as a number, the value is treated as if it would be a number. If the value of this property is a string starting with "/", this value is applied as a prefix, regardless of the configured search paths! If the value is anything else, it is ignored. If this property is not specified, it defaults to the default configuration of the sling servlet resolver.

 

 

 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

The sling.servlet.prefix property in AEM is used to define the order of servlet resolution. It's not related to the URL or resource type of your servlet.

 

In Sling, all servlets and scripts are resources, and they're all stored under /apps or /libs. The sling.servlet.prefix property is used to define a search path for these resources. The default value is -1, which means that Sling will search in /apps and /libs for the servlet or script.

The sling.servlet.prefix property can be a number or a string. If it's a number, it's used as a priority. A higher number means a higher priority. If it's a string, it's used as a path. Sling will search for the servlet or script in this path.

 

https://sling.apache.org/documentation/the-sling-engine/servlets.html#:~:text=If%20the%20value%20of%....

 

sling.servlet.prefix

 

The prefix or numeric index to make relative paths absolute. If the value of this property is a number (int), it defines the index of the search path entries from the resource resolver to be used as the prefix. The defined search path is used as a prefix to mount this servlet. The number can be -1 which always points to the last search entry. If the specified value is higher than than the highest index of the search paths, the last entry is used. The index starts with 0. If the value of this property is a string and parseable as a number, the value is treated as if it would be a number. If the value of this property is a string starting with "/", this value is applied as a prefix, regardless of the configured search paths! If the value is anything else, it is ignored. If this property is not specified, it defaults to the default configuration of the sling servlet resolver.