| Author |
HFS Mack Exam Q22 - Page 772 - ResquestDispatcher - Is the answer correct?
|
Justin
Greenhorn
Joined: Sep 10, 2004
Posts: 6
|
|
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?
|
 |
Nicholas Cheung
Ranch Hand
Joined: Nov 07, 2003
Posts: 4982
|
|
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
|
SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
|
 |
Roger Yates
Ranch Hand
Joined: Aug 31, 2004
Posts: 118
|
|
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!
|
Cheers,<br />Roger<br />SCJP 1.2, 1.4, SCBCD 1.3, SCWCD 1.4
|
 |
Neil Mc
Ranch Hand
Joined: Oct 20, 2003
Posts: 32
|
|
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.
|
 |
pallavi utukuri
Ranch Hand
Joined: Feb 10, 2004
Posts: 182
|
|
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?
|
Thanks,<br />Pallavi
|
 |
Shiang Wang
Ranch Hand
Joined: Jun 20, 2003
Posts: 96
|
|
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
|
SCBCD, SCWCD, SCJP
|
 |
pallavi utukuri
Ranch Hand
Joined: Feb 10, 2004
Posts: 182
|
|
|
oooh i missed out that! good point
|
 |
Sudhakar Namasivayam
Greenhorn
Joined: Sep 09, 2004
Posts: 11
|
|
Is this correct ??? <%jsp:include page="/segments/footer.html" %> Should it not be <jsp:include page="/segments/footer.html"/>
|
Regards,<br />Sudhakar<br /> <br />SCJP 1.4
|
 |
pallavi utukuri
Ranch Hand
Joined: Feb 10, 2004
Posts: 182
|
|
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
|
 |
 |
|
|
subject: HFS Mack Exam Q22 - Page 772 - ResquestDispatcher - Is the answer correct?
|
|
|