• 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

WhizLabs Question : RequestDispatcher - Please help me out

 
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
reply
    Bookmark Topic Watch Topic
  • New Topic