• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Why is the include JSP Standard Action like SSI?

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regarding HFS&JSP 2nd Ed. page 426, question 12.

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);
 
Ranch Hand
Posts: 310
1
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Timothy Stone wrote:Regarding HFS&JSP 2nd Ed. page 426, question 12.

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.
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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);




Hi.

I just read on Wikipedia about SSI (never used it), SSI is about the text, and there it says
http://en.wikipedia.org/wiki/Server_Side_Includes

DIRECTIVE:
include

PARAMETER:
file, direct or virtual

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)

I'm accedentally 'totally into this', learning it at the moment, now.

Bye.Bye
 
Petar Thomas
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...Aha....D has dispatcher.include
 
Petar Thomas
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why C is more than D ???

is the rightier question.
 
Creator of Enthuware JWS+ V6
Posts: 3412
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Timothy, Rajeev and Petar,

The original question:

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.


Regards,
Frits
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question is not fair!

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.

By pointing out these arguments, A B and D seem all correct.
 
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
D is not correct, as this is a pure Java code and not a scriptlet. It lacks the <% ... %> construct.

Cheers!
 
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<jsp:include> is correct one since this includes the dynamic content to the response output stream buffer...

This construct generates dynamic content based on the request it receives...

and this action is performed at the run time...

and

<%@include %> directive can be used to include the static content... and the inclusion of code is done "at" compile time itself...

Its something similar to "Preprocessor directives" in C... which is done before compile time...

If there is a common code which has to be used in multiple JSPs... Instead of writing the common code in all JSPs repeatedly...

It can be put in one JSP and can be included in multiple JSPs with one line statement <%@include %>

 
Piotr Nowicki
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Cheers!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic