JSP content in sightly
Asked Answered
D

2

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?

Different answered 21/3, 2016 at 9:56 Comment(4)
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.Dunlap
what about html file saved as html which contains jsp related code inside? This works in sightly!!Different
It will print jsp code as normal text.Sandman
No! In a regular HTML, jsp content is printed as normal text, but in sightly it doesn't.Different
A
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.

Actually answered 25/9, 2017 at 9:24 Comment(0)
A
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>
Agronomics answered 2/4, 2016 at 19:8 Comment(0)
A
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.

Actually answered 25/9, 2017 at 9:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.