1

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: enter image description here

Is there any difference between them?

Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142
Y.L.
  • 1,274
  • 6
  • 23
  • 39
  • No, there is no difference – jmj Jun 25 '14 at 14:50
  • @JigarJoshi what about page context attributes? Isn't their scope related to the current JSP page only? Also, a variable in a higher scope can be declared in a JSP file A and be used in JSP files included into this file A. – Luiggi Mendoza Jun 25 '14 at 14:53
  • @JigarJoshi: If that's true then what's the purpose of the whole sentence? – Bhesh Gurung Jun 25 '14 at 14:53

4 Answers4

1

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.

Community
  • 1
  • 1
Federico Piazza
  • 30,085
  • 15
  • 87
  • 123
  • From the text, you're still quoting JSP file and JSP page which shows them as different concepts. IMO the 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. – Luiggi Mendoza Jun 25 '14 at 15:01
  • @LuiggiMendoza good point! Didn't pay attention to that. I'll update my answer with that. Thanks – Federico Piazza Jun 25 '14 at 15:03
1

I believe following is what that means -

  • JSP file - the actual .jsp file, file as in the filesystem.
  • JSP page - the result of compilation of the .jsp file, that's currently serving the request

Please also check this answer here - https://stackoverflow.com/a/14763794/738746.

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

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

Community
  • 1
  • 1
Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142
1

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:

  • dir/
    • file1.jsp
    • file2.jsp
  • file2.jsp
  • index.jsp

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.

izstas
  • 5,004
  • 3
  • 42
  • 56
1

Single JSP page may be built from several JSP files.

So JSP page is not the same as JSP file.

Kasper Ziemianek
  • 1,329
  • 8
  • 15
  • What's the question ? I see ... Is there any difference between a JSP file and a JSP page? If they're not the same, it means that there is a difference. – Kasper Ziemianek Jun 30 '14 at 15:40