Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HF final mock exam Q22

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Today I've made the HF final mock exam (i have the real exam on friday). I don't agree with solution to Q22.
--------------------------------------------------------
Q22. Which JSP code would you use to include static content in a JSP?
A. ...
B. ...
C. <jsp:include page="/segments/footer.html" />
D. ...
--------------------------------------------------------

Option C is marked as true. I think it shouldn't be marked as true, since the content could be dynamic.

In JSP spec (section 5.4) you can read an equivalent example:
<jsp:include page=�/templates/copyright.html�/>
and the spec says:
"It is likely a static object, but it could be mapped into, for instance, a servlet via web.xml."

So, the fact that the extension is .html doesn't mean that it is a static resource, since "/segments/footer.html" could be a totally ficticious name mapped to a servlet via the DD.

What do you think about it?

(BTW, I scored 71% in the HF exam. It's a really hard exam. I hope the real one to be easier )
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. I agree. The answer to Mock Exam Q22 is "A". Only the include directive adds static content in a JSP.
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does Option A says. I agree Option C is not right answer.
---------------------------------------
<jsp:include page="somefile" />
---------------------------------------
is a dynamic call.
---------------------------------------
<%@ include file="anothefile" %>
---------------------------------------
is a static call

My assumption is when the page is precompiled a dynamic call is never precompiled even if it is refering to a static page.
[ April 14, 2005: Message edited by: jiju ka ]
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, from one point of view, HFS is not wrong.

<jsp:include> can really be used to include static content in a page!

Which are the other options?
 
Jose Esteban
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vani Kadur:
Only the include directive adds static content in a JSP.


Nope. According to JSP.5.4:
"A <jsp:include .../> action provides for the inclusion of static and dynamic resources in the same context as the current page."

So the include action can also add static content (for example, a HTML page). The question is that writing:

<jsp:include page="/segments/footer.html" />

doesn't mean that you are including the HTML page because, perhaps, the url-pattern "/segments/footer.html" is mapped to a JSP in the DD:

Then, when the include action is invoked, the container is really including /someJSP.jsp.

Hope this clarifies the answer.
 
Jose Esteban
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rafael Pereira:
Well, from one point of view, HFS is not wrong.

<jsp:include> can really be used to include static content in a page!


Would you use

<jsp:include page="/segments/footer.html" />

to include static content when there's no guarantee that the content included is really static? I wouldn't.

Originally posted by Rafael Pereira:

Which are the other options?


The correct option is:
A. <%@ include file="/segments/footer.html" %>
 
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, this is an argument of semantics. Jose is technically correct, and if this were a real question on the exam he would be able to appeal it. (I think... I have never tried to configure a mapping with that kind of url pattern, but I assume it will work)

However, I think that the mock exam assumes that no extravagant mapping has taken place, and they are trying to reinforce the fact that the <jsp:include> standard action is able to include static content as well as dynamic.

Perhaps you should submit your suggestion to the errata page at oreilly press and have them add a clause like
---------
C. <jsp:include page="/segments/footer.html" /> (Assume that /segments/footer.html is a valid html page and no url remapping has taken place)
---------
 
Jose Esteban
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Bourdeaux:
I have never tried to configure a mapping with that kind of url pattern, but I assume it will work


I did it, and it works.

Originally posted by Paul Bourdeaux:
However, I think that the mock exam assumes that no extravagant mapping has taken place,


Too much assumption for an exam!! Moreover, Spec JSP.5.4 warns explicity about this possibility:
"<jsp:include page="/templates/copyright.html"/>
It is likely a static object, but it could be mapped into, for instance, a servlet via web.xml."

Originally posted by Paul Bourdeaux:
... have them add a clause like
---------
C. <jsp:include page="/segments/footer.html" /> (Assume that /segments/footer.html is a valid html page and no url remapping has taken place)
---------


I agree. It would be a correct wording.
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I opened my copy of the specs, and I have to conceed that Jose is absoluty correct. Looking closely at the answer, there is no explanation for Answer C like therre is for Answer A, so I believe it was erronously marked.

I am going to submit it as errata at the O'Reilly HFS&J page. Good catch Jose.
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As promised, I sumbitted an errata, and recieved the following response. I thought I would post it here as well.

>Reporter: Paul Bourdeaux
> Email: pbourdeaux@cait.org
> Title: Head First Servlets and JSP
> Page: 810
> Location: Answer to Question 22
> Severity: serious technical mistake
>
> ======================= Description =======================
>
> [810] Answer to Question 22;
> Answer C is incorrectly marked as a right answer. According to the
> JSP 2.0 Specs, section 5.4 page 1-109, the included object is
> "likely a static object, but it could be mapped ito, for instance,
> a servlet via web.xml." There is no way to tell if
> /segments/footer.html is static or dynamic, therefore Answer C is
> incorrect.
>
> The only correct answer is Answer A.

Date: Sun, 1 May 2005 13:04:28 -0700 (PDT)
From: Bryan Basham

No errata.

This question is not meant to make the reader challenge whether
the URL "/segments/footer.html" is truly static or if it has
been mapped to some servlet. That is not the point of the
question. The point is whether the include directive *as well as* the
include action can include static content. The answer is "yes, they
both permit static content", so both A & C are valid options.

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
guys, i'm a bit relieved. I hope such stupid ques don't pop up on my test. I had posted a message regarding the same question, cos while taking the test, even i marked ONLY A.

Anyways, i find teh question no. 55 also errorneous. Any help on tat front?
 
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic