Reputation:
A JSP file, like a HTML file can be requested directly in url. However, a JSP file gets compiled during runtime and HTML file doesn't (Although they are both requested the same way). Even a JSP file with no dynamic content gets compiled during runtime because they get converted into servlets internally. We can include a HTML file inside a JSP file but not the other way around. There are so many components involved in providing resource to the user (Servlets
, Request
, Response
, Webserver
etc).
Which component decides whether the file needs to be compiled by looking at its extension?
Sightly is a HTML file and can contain JSP code within its body which ideally shouldn't get compiled but does. How?
Upvotes: 6
Views: 6160
Reputation: 217
Sightly can only be included as part of a component. Although sightly is HTML5 (ends with .html), sightly gets compiled by Sightly engine
.
So it is possible to have a sightly file that includes JSP file.
Upvotes: 2
Reputation: 1066
Not entirely sure I understand what your questions are, but here's my attempt
If there are no Servlets defined for a path then Apache Sling will figure out which "scripting engine" to use based on things like the http request method and the extension (.jsp vs .html). See here. It's up to the engine (e.g. the JSP engine or the Sightly engine) to figure out what to do with the request after that.
If you have JSP code written inside a sightly file it will simply get printed out in the response. I've tested this using the Sightly Repl on my localhost.
so a sightly file foo.html
with contents
<c:set var="foo" value="bar"/>
<div>${foo}</div>
Results in a response that looks like this.
<c:set var="foo" value="bar"/>
<div></div>
You can see that Sightly doesn't anything to strip out or evaluate the jsp tag. the ${foo}
would go away because there is no Sightly variable called foo in scope.
Another note: You can actually include a JSP file from Sightly.
Here's an example from Adobe's docs:
<section data-sly-include="path/to/template.jsp"></section>
Upvotes: 3