6

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).

  1. Which component decides whether the file needs to be compiled by looking at its extension?

  2. Sightly is a HTML file and can contain JSP code within its body which ideally shouldn't get compiled but does. How?

  • All JSP files are converted in to Serlvet. Once converted its not recompiled unless JSP file is modified. Even a simple HTML file saved as jsp will get converted in to servlet. – asb Mar 21 '16 at 15:36
  • what about html file saved as html which contains jsp related code inside? This works in sightly!! –  Mar 21 '16 at 16:10
  • It will print jsp code as normal text. – Dhruv Kapatel Mar 21 '16 at 17:49
  • No! In a regular HTML, jsp content is printed as normal text, but in sightly it doesn't. –  Mar 22 '16 at 00:10

2 Answers2

3

Not entirely sure I understand what your questions are, but here's my attempt

  1. 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.

  2. 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>
Jordan Shurmer
  • 946
  • 7
  • 21
2

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.

Raghavendra N
  • 209
  • 8
  • 25