aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes WhizLabs Question : RequestDispatcher - Please help me out 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 "WhizLabs Question : RequestDispatcher - Please help me out" Watch "WhizLabs Question : RequestDispatcher - Please help me out" New topic
Author

WhizLabs Question : RequestDispatcher - Please help me out

Edisandro Bessa
Ranch Hand

Joined: Jan 19, 2006
Posts: 584
Hi guys,

Could you please help me out ?

Question :

Assuming that request is the ServletRequest object and context is the ServletContext object. Which of the following request dispatcher elements will correctly fetch the dispatcher to the "ControllerServlet" ?

The code is executed from the "RedirectServlet".

web.xml of "whiz" web application.



a) context.getRequestDispatcher("/whiz/ControllerServlet");
b) request.getRequestDispatcher("ControllerServlet");
c) request.getRequestDispatcher("/whiz/ControllerServlet");
d) context.getRequestDispatcher("/ControllerServlet");
e) context.getRequestDispatcher("ControllerServlet");
f) context.getNamedDispatcher("ControllerServlet");
g) context.getNamedDispatcher("/ControllerServlet");
h) request.getNamedDispatcher("/ControllerServlet");

I chose options D and F but according to WhizLabs the correct options are B, D and F.

Why B is correct ?
Once the request is executed from the /Redirect path, requesting such dispatcher I would get a /Redirect/ControllerServlet which is not mapped in DD, right ?

Did I forget anything ?

Oh, can <servlet-name> element come after the <servlet-class> element ?
I thought it was the opposite.


"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself
Kishore Balla
Ranch Hand

Joined: Jun 08, 2005
Posts: 165
Originally posted by Edisandro Bessa:

Why B is correct ?
Once the request is executed from the /Redirect path, requesting such dispatcher I would get a /Redirect/ControllerServlet which is not mapped in DD, right ?



This will match with url-pattern /Redirect/* which was mapped to servlet named RedirectServlet


Originally posted by Edisandro Bessa:

Did I forget anything ?

Oh, can <servlet-name> element come after the <servlet-class> element ?
I thought it was the opposite.


Order was important till Servlets 2.3 and no more important in Servlets 2.4


SCJP 5.0 : 88% My Story, SCWCD 1.4 : 94% My Story
kishoreballa.com
Edisandro Bessa
Ranch Hand

Joined: Jan 19, 2006
Posts: 584
Thanks Kishore for your prompt reply.


Kishore wrote ...
Order was important till Servlets 2.3 and no more important in Servlets 2.4


Regarding the above information, I really didn't know about it. Thanks a lot.


Kishore wrote ...
This will match with url-pattern /Redirect/* which was mapped to servlet named RedirectServlet


Regarding the above affirmation, it's exactly where I got confusing.

The question asks : Which of the following request dispatcher elements will correctly fetch the dispatcher to the "ControllerServlet" ?

As per your previous explanations and as I would expect, choice B will map the request to RedirecServlet and NOT to ControllerServlet as the question asks.

Based on that, Am I still wrong ?
 
 
subject: WhizLabs Question : RequestDispatcher - Please help me out