• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP file location in a directory hierarchy

 
Jerry Bustamente
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,

I found this mock exam question and do not understand the answer.

Can anyone help me understand? I've been staring at this for a while and just can't figure it out.

Question:

Given four JSP files arranged in the following directory hierarchy, identify the correct action that should be defined in acme/detonate.jsp to display 'click' when coyote.jsp is requested.

coyote.jsp
dynamite.jsp
acme/detonate.jsp
acme/dynamite.jsp
coyote.jsp contains <%@ include file="acme/detonate.jsp %>
dynamite.jsp contains boom!!!
acme/dynamite.jsp contains click

Possible answers:

1 <jsp:include page="dynamite.jsp"/>
2 <jsp:include page="acme/dynamite.jsp"/>
3 <jsp:include page="../dynamite.jsp"/>
4 <jsp:include file="dynamite.jsp" />

Answer 2 is correct because the page attribute in the jsp:include action is interpreted relative to the current JSP page, that is coyote.jsp since detonate.jsp is included at translation-time of coyote.jsp. Therefore the dynamite.jsp located in the acme directory is required by coyote.jsp to display 'click'.

Answer 1 is incorrect because coyote.jsp would include the file dynamite.jsp from the same directory which would display 'boom!!!'. Answer 3 is incorrect because coyote.jsp would attempt to include dynamite.jsp from its parent directory which does not exist. Answer 4 is incorrect because jsp:include is incorrectly defined. The file atttribute is not supported by this action.

Thanks much.

Sincerely,

Jerry B.
 
botn ora
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jerry,

Given four JSP files arranged in the following directory hierarchy, identify the correct action that should be defined in acme/detonate.jsp to display 'click' when coyote.jsp is requested.

coyote.jsp
dynamite.jsp
acme/detonate.jsp
acme/dynamite.jsp
coyote.jsp contains <%@ include file="acme/detonate.jsp %>
dynamite.jsp contains boom!!!
acme/dynamite.jsp contains click

Possible answers:

1 <jsp:include page="dynamite.jsp"/>
2 <jsp:include page="acme/dynamite.jsp"/>
3 <jsp:include page="../dynamite.jsp"/>
4 <jsp:include file="dynamite.jsp" />


<%@include will include the code statically. We need to write something in acme/detonate.jsp. But, the code of this file is now the part of coyate.jsp directly. So, the line <jsp:include page="acme/dynamite.jsp" /> is the part of coyate.jsp not acme/detonate.jsp. Now, it is easy to see from coyate.jsp that it should be the choice 2.



Thanks.
 
Jerry Bustamente
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your kind reply. I understand now.

Sincerely,

Jerry B.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic