JSP content

A JSP file, such as an HTML file, can be requested directly in the URL. However, the JSP file is compiled at runtime, and the HTML file is not (although both are requested the same way). Even a JSP file without dynamic content is compiled at run time because it is internally converted to servlets. We can include the HTML file in the JSP file, but not vice versa. There are so many components associated with providing a resource to a user ( Servlets , Request , Response , Webserver , etc.).

  • Which component decides whether to compile a file by looking at its extension?

  • Sight is an HTML file and may contain JSP code inside its body, which ideally should not be compiled, but done. How?

+5
source share
2 answers

A look can only be included as part of a component. Although the sight of HTML5 (ends with .html), the Sightly engine clearly compiled. Thus, it is possible to have a visible file that includes the JSP file.

+2
source

Not quite sure that I understand what your questions are, but here is my attempt

  • If there is no servlet for the path, then Apache Sling will determine which "scripting mechanism" to use based on such things as the HTTP request method and extension (.jsp vs .html). See here . It is up to the engine (like 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 visible file, it will simply be printed in response. I tested this using Sightly Repl on my localhost.

so the spectacular file foo.html with the contents

 <c:set var="foo" value="bar"/> <div>${foo}</div> 

The result is in the answer, which is as follows.

 <c:set var="foo" value="bar"/> <div></div> 

You can see that Sightly does nothing to cut or evaluate the jsp tag. ${foo} will disappear because there is no visible variable called foo in scope.


Another note. In fact, you can include the JSP file from Sightly.

Here is an example from Adobe docs :

 <section data-sly-include="path/to/template.jsp"></section> 
+2
source

Source: https://habr.com/ru/post/1245472/


All Articles