Get your CodeRanch badge!*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes doubt on RequestDispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "doubt on RequestDispatcher" Watch "doubt on RequestDispatcher" New topic
Author

doubt on RequestDispatcher

koteswararao arvapalli
Greenhorn

Joined: Mar 26, 2008
Posts: 13
Hi,

i have seen problem in question bank that is:
public void doGet(HttpServletRequest req, HttpServletResponse res)

{

try

{

RequestDispatcher rd = this.getServletContext().getRequestDispatcher("Login.jsp"); // 1

rd.forward(req, res); // 2

}

catch(Exception e)

{

e.printStackTrace();

}

}

Select 2 correct options.
A.This will not compile.
B.This will compile but will not work as expected.
C.This code will work just fine.
D.It will compile but not work properly if //1 is replaced with: RequestDispatcher rd = req.getRequestDispatcher("Login.jsp");
E.It will compile and will work properly if //1 is replaced with: RequestDispatcher rd = req.getRequestDispatcher("Login.jsp");


i think answer are B,E.

But answers are C,E.

is it correct? can you give me some explanation upon it?

Regards,
koti
Dan Walin
Ranch Hand

Joined: Nov 11, 2003
Posts: 109
I looked at the question and before I saw the answers, I assumed the correct choices were C and E. My reason would be that I don't see any reason why it would on work and would also work if the RequestDispatcher was created from the request object. I know there is a difference between the two ways that affects the path that can be used (I forget this and need to re-read up on it) but I don't think we have any information in the question that would make us think there would be a path problem.
koteswararao arvapalli
Greenhorn

Joined: Mar 26, 2008
Posts: 13
Hi Dan,
i am sure that "the path string passed to ServeletContext.getRequestDispatcher() must start with '/' "
what do you say?

Regards,
koti.
Shruthi Karthick
Ranch Hand

Joined: Mar 12, 2008
Posts: 45
option c is incorrect. This code wont work as such.
If we get RequestDispatcher from ServletContext we cannot specify relative path in argument of getRequestDispatcher().
The path should start with forward slash.
So options B and E are correct.


Shruthi Karthick<br />SCJP - 93%<br />SCWCD - 89%
Dan Walin
Ranch Hand

Joined: Nov 11, 2003
Posts: 109
Thanks - I need to restudy that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt on RequestDispatcher
 
Similar Threads
doubts getRequestDispatcher
Problem in Mock exam
RequestDispatcher question
Mock exam questions...
SCWCD mock questions II