问题
I was looking over how sling will call the script on the basis of url. In the case of selector it seems work fine but if i use no selector, its confusing for me to understand:
I have a page /content/AEMProject/English/test.html
which has resourceType AEMProject/components/page/basepage
resouce basepage has 4 script files : basepage.html.jsp , basepage.jsp , html.jsp, GET.jsp
. I red the Sling Best Match concept. So i have two strange cases.
1) My basepage.html.jsp
is executing, as i consider it as best match. In case i delete this file html.jsp
execute but i consider basepage.jsp
as the 2nd best case.
2) In case i delete basepage.html.jsp , basepage.jsp , html.jsp
files my GET.jsp
doesn't render.
I am considering here basepage as selector or IS is not.
Thanks
回答1:
Quoting from the sling docs the rules for script path priorization is defined as follows:
- The more request selectors are matched, the better.
(Note that a script with more than one selector doesn't get selected i.e, if you have a script x.y.jsp, where x and y are your selectors, it is ignored by sling. But it would still select the script y.jsp
, present inside a folder x
i.e., If the request is for test.x.y.html, then
-basepage
|_x
|_y.jsp (selected)
|_x.y.jsp (ignored)
|_x.jsp (selected in case x/y.jsp is not present. The script containing the first selector is chosen in such cases.)
A script including the request extension matches better than one without a request extension (for html only)
A script found earlier matches better than a script found later in the processing order. This means, that script closer to the original resource type in the resource type hierarchy is considered earlier.
So now to answer your questions,
Your html.jsp would always take preference over your component.jsp, not the other way round.
Your GET.jsp should execute in the worst case scenario, i.e., when none of the other files are present, unless you have inherited this from some other component.
来源:https://stackoverflow.com/questions/27213555/sling-resolution-script-calling-order