Why is the include JSP Standard Action like SSI?

I have looked at some of the answers from c. 2007, but nothing directly asking the question, Why is Answer C more correct than Answer A.

Sure the comments on the answer provide some context to the author's thinking, but I have used "SSI" in Apache and Tomcat, and the include standard action and the directive provide SSI-like functionality as I have used SSI in the past. Is it the "dynamic content" phrasing that makes C more correct than A?

The question is provided below for context.

Thanks!
Tim

How would you include dynamic content in a JSP, similar to a server-side include (SSI)? (Choose all that apply.)
A. <%@ include file=”/segments/footer.jspf” %>
B. <jsp:forward page=”/segments/footer.jspf” />
C. <jsp:include page=”/segments/footer.jspf” />
D. RequestDispatcher dispatcher = request.getRequestDispatcher(“/segments/footer.jspf”); dispatcher.include(request,response);

I have looked at some of the answers from c. 2007, but nothing directly asking the question, Why is Answer C more correct than Answer A.

Sure the comments on the answer provide some context to the author's thinking, but I have used "SSI" in Apache and Tomcat, and the include standard action and the directive provide SSI-like functionality as I have used SSI in the past. Is it the "dynamic content" phrasing that makes C more correct than A?

The question is provided below for context.

Thanks!
Tim

How would you include dynamic content in a JSP, similar to a server-side include (SSI)? (Choose all that apply.)
A. <%@ include file=”/segments/footer.jspf” %>
B. <jsp:forward page=”/segments/footer.jspf” />
C. <jsp:include page=”/segments/footer.jspf” />
D. RequestDispatcher dispatcher = request.getRequestDispatcher(“/segments/footer.jspf”); dispatcher.include(request,response);

The question is asking

How would you include dynamic content in a JSP, similar to a
server-side include (SSI)? (Choose all that apply.)

Since the include directive (which is static) happens at the JSP translation time and the include standard action (which is dynamic) occurs at runtime, standard action is the better / correct answer in this case.

DESCRIPTION:
This is probably the most used SSI directive, allowing the content of one document to be included in another. The file or virtual parameters specify the file (HTML page, text file, script, etc) to be included. The file parameter defines the included file as relative to the document path; the virtual parameter defines the included file as relative to the document root.

Here, important part is: THE CONTENT OF ONE DOCUMENT

There is also AN OUTPUT OF ONE (document?, file?)... JSP..... (let's say)

Small confusment is "THE CONTENT OD ONE DOCUMENT", which to an eye of an naive observer IS THE OUTPUT OF ... JSP.... Like Word document, content is that text, but actually content IS the CODE... (let's say code). That's just the small confusment...

So, We have 2:

- <% include .....
- <jsp:include ......

1. DIRECTIVE
2. STANDARD ACTION

Let's say that the name of the file being "included" is: "Header.jsp". So, the 'code' of that file is:

Nevermind my personality.

1. -including- that file with directive:

2. -including- that file with standard action

- attributes are different ( file and page )
(-and there shouldn't be html&body tags in file that is being included, more or less)

NOW:
The poant is that JSP will be translated, or compiled, or something like that, I'm not enough sure, TO THE SERVLET.

-my small nofusment in this moment is: "What if the file being included is HTML? How can it be translated into a servlet? Maybe it just cant."

So, anyway:

GENERATED SERVLET CODE FOR THE (header file) file being -included- :

1... GENERATED SERVLET CODE FOR THE JSP USING
INCLUDE DIRECTIVE

2.GENERATED SERVLET CODE FOR THE JSP USING
<JSP:INCLUDE> STANDARD ACTION

The include directive inserts the SOURCE of "Header.jsp" at translation time. But the <jsp:include/> standard action inserts the RESPONSE of "Header.jsp", at runtime

Here, actualy, the key points are also request and response objects, but also, in "this story" there is important how to pass some parameter to the 'file' (?) being included, becaouse it is needed not only to 'include' but to customize the 'includee'. This thing is observable from the question. The question is nice. Forward page and request dispatcher "don't include". The question is nice becaouse of all of things that it shows, req&resp objects "travelling", output composing, etc. , and even the use of attributes and parameters not visible in the question.

What else?

-include directive at first request does the work, and from the second there is no extra runtime overhead
-include standard action has less work at translation time, and more work with -each- request (especially if the included file is JSP)
- Can any of two of them change the headers, or set cookies? (I'm not sure what I read, but I think I read NO)

-if the file being included changes, most servers will retranslate, but it is not guaranteed.

-customization is done with <jsp:param> (and probablly attributes in request can "travell" )

- <jsp:forward> flushes the buffer, and then forwards ( flush-and-forward) (..and I think that I understood that in that case an exception is thrown "visible on the old page" that was flushed)... so , if anything exsisted on the PAGE before the 'forward' it was cleared (BUFFER)

Is it the "dynamic content" phrasing that makes C more correct than A?

Yes, that is correct. Both are forms to include a file: one done in the translation phase and the other at request time.

According to the specifications JSP.1.10.3 The include Directive

A JSP container can include a mechanism for being notified if an included file changes, so the container can recompile the JSP page. However, the JSP 2.0 specification does not have a way of directing the JSP container that included files have changed.

So it should actually be used for static content lik copyright symbols, page header and so on: things that hardly ever change as you are not sure whether the container will recompile the page.

and a little bit further on JSP.1.10.5 Including Data in JSP Pages

An include directive regards a resource like a JSP page as a static object; i.e. the text in the JSP page is included. An include action regards a resource like a JSP page as a dynamic object; i.e. the request is sent to that object and the result of processing it is included.

Despite the fact that we should avoid using include directive for things we know that may change in the future, it can STILL be used for dynamic content due the fact we can include JSP code (which provides dynamic behavior), for example. That makes alternative A correct, in my opinion.

Plus, alternative D is also correct! It is similar to alternative C, the question does not say we could not use scriptlets in our JSPs.

Well, as the D option is 100% incorrect because of the reason I pointed above, the A can be not so obvious in my opinion.

It is true, that the container when sees the include directive, is including this file (not page) during translation time, so it is used mainly for static content which is not a subject of dynamic changes.
But it doesn't mean you cannot add a dynamic content in the included file. As an example:

test3.jsp

test.jsp

The result for request:

http://localhost:8080/myApp/test.jsp?test=Howdy%20Rachners

is

Including static file: The Request parameter 'test' is equal to: Howdy Rachners. End of static included file. After inclusion.

So, it's different in case different test parameter is set. The inclusion is static, but it may introduce some dynamic features.

The point is, that you cannot change the test3.jsp file without recompilation of test.jsp. This is what dynamic is referring to in the cited question.