• 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

HFS Mack Exam Q22 - Page 772 - ResquestDispatcher - Is the answer correct?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
22. Which JSP code would you use to include static content in a JSP?

a. <%@ include file="/segments/footer.html" %>
b. <%@ forward page="/segments/footer.html" %>
c. <%jsp:include page="/segments/footer.html" %>
d. RequestDispatcher dispatcher = request.getRequestDispatcher("/segments/footer.html");
dispatcher.include(request,response);

The answer for the above question was given as (a) and (c)

My question is - Why is (d) not a correct answer too?

If not why?
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For Dispatcher that obtained via ServletRequest, the URL must be RELATIVE PATH. Thus, D is not correct.

For Dispatcher that obtained via ServletContext, the URL could be either relative or absolute.

Nick
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I took a more simplistic approach.
For d. to be correct it would need to be part of a scripting section:

though as Nick pointed out, it wouldn't be valid even if it was as above!
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought there may have been an error with this question as well, but for a different reason.

I thought that the only correct answer should be (a) i.e. NOT (c) as a <jsp:include> is used to include dynamic content and the question distinctly asks how you should include static content.
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think C is definetely correct as:
<jsp:include>:
1.The <jsp:include> element allows you to include either a static or dynamic resource in a JSP page.
2.If the resource is static, its content is included in the calling JSP page.
3.If the resource is dynamic, it acts on a request and sends back a result that is included in the JSP page

comming to option D:
RequestDispatcher from request :
1.The pathname specified may be relative, although it cannot extend outside the current servlet context.
2.If the path begins with a "/" it is interpreted as relative to the current context root.
3.If the path does not start with "/" its considered relative to original request.
4.The resource can be dynamic or static.

soo A,C and D are correct answers....
am i ryt?
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Relative path can start with '/' or without.
When it starts with "/", it means that it is relative to the context root.
When it starts without "/", it means that it is relative to the current servlet or jsp.
But RequestDispatcher you get via ServletContext must start with "/", or you will get this exception.
org.apache.jasper.JasperException: Path included.jsp does not start with a "/" character
RequestDispatcher you get via ServletRequest can start with or without "/" depends on what you need. Therefore the answer D is invalid not because of the path, but the missing <% %>

Shiang
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oooh i missed out that! good point
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this correct ??? <%jsp:include page="/segments/footer.html" %>


Should it not be <jsp:include page="/segments/footer.html"/>
 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yaa this is wrong! <%jsp:include page="/segments/footer.html" %>
it must b <jsp:include page="/segments/footer.html" />
i must b blind not to see that

so that means C is not a Correct option
 
reply
    Bookmark Topic Watch Topic
  • New Topic