I was reading the JSP Specification 2.1, the chapters about the JSP include directive and JSP include tag, a lot of places talk about the "JSP file" and "JSP page" seperately, such like:
Is there any difference between them?
I was reading the JSP Specification 2.1, the chapters about the JSP include directive and JSP include tag, a lot of places talk about the "JSP file" and "JSP page" seperately, such like:
Is there any difference between them?
Usually, there is no difference when we speak about jsp file or jsp page but a good observation from LuiggiMendoza is:
JSP file is the physical file stored in your hard drive while the JSP page is the result of evaluating the JSP file from an application server.
But there is a difference when using directives:
<jsp:include page="page.html" />
and also <%@include file="page.html"%>
.
You can find an interesting post about it:
What is the difference between <jsp:include page = ... > and <%@ include file = ... >?
And a nice explanation here:
<%@ include file="filename" %> is the JSP include directive. At JSP page translation time, the content of the file given in the include directive is ‘pasted’ as it is, in the place where the JSP include directive is used. Then the source JSP page is converted into a java servlet class. The included file can be a static resource or a JSP page. Generally JSP include directive is used to include header banners and footers. The JSP compilation procedure is that, the source JSP page gets compiled only if that page has changed. If there is a change in the included JSP file, the source JSP file will not be compiled and therefore the modification will not get reflected in the output.
< jsp:include page="relativeURL" /> is the JSP include action element. The jsp:include action element is like a function call. At runtime, the included file will be ‘executed’ and the result content will be included with the soure JSP page. When the included JSP page is called, both the request and response objects are passed as parameters. If there is a need to pass additional parameters, then jsp:param element can be used. If the resource is static, its content is inserted into the calling JSP file, since there is no processing needed.
I believe following is what that means -
.jsp
file, file as in the filesystem..jsp
file, that's currently serving the requestPlease also check this answer here - https://stackoverflow.com/a/14763794/738746.
The include directive:
<%@ include file="header.html" %>
Static: adds the content from the value of the file attribute to the current page at translation time. The directive was originally intended for static layout templates, like HTML headers.
The
<jsp:include>
standard action
<jsp:include page="header.jsp" />
Dynamic: adds the content from the value of the page attribute to the current page at request time. Was intended more for dynamic content coming from JSPs.
JSP page refers to a "top-level JSP file", which, as defined in JSP.1.1.8:
invoked directly by the client or dynamically included by another page or servlet
While JSP file may refer to a file which, for example, gets statically included.
To illustrate your quote, consider following directory structure:
Let's say you have <%@include file="dir/file1.jsp" %>
in your index.jsp. If you put <%@include file="file2.jsp" %>
in dir/file1.jsp, it will include dir/file2.jsp, while if you put <jsp:include page="file2.jsp" />
, it will include file2.jsp next to index.jsp.
Single JSP page may be built from several JSP files.
So JSP page is not the same as JSP file.