• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[HFSJ 2nd Edition] chapter 5 Mock Exam Question # 15

 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which are true about the RequestDispatcher interface? (Choose all that apply.)
A. Of its two methods, forward() is used most frequently.
B. Its methods take the following arguments: a resource, a request, and a response.
C. Depending on the class whose method creates a RequestDispatcher, the path to the resource to be forwarded to will change.
D. Regardless of the class whose method creates a RequestDispatcher, the path to the resource to be forwarded to will NOT change.
E. If your servlet invokes RequestDispatcher.forward, it can send its own response

The options A and C are the correct one. I know how option A is correct. But I couldn't find how option C is correct and options D and E are incorrect.
 
Shilpa Shandilya
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vishal,

A RequestDispatcher object can be created in 2 ways, either by using the request or servletContext object.

When it is created using request, the resource path is a relative path and given without a forward slash. Wheras when it is created using ServletContext, the resource path is absolute path startinng witha forward slash. That is why option C is correct and not D.

Hope it helped.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, about option E

If your servlet invokes RequestDispatcher.forward, it can send its own response.

if your servlet not invokes RequestDispatcher.forward ,then also it can send its own response. right?

please correct me ,if i am wrong
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by seetharaman venkatasamy:
if your servlet not invokes RequestDispatcher.forward ,then also it can send its own response.
How?
 
Vishal Chugh
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

See when you dont want to use the forward method , still you want to send the response , then how?

Please refer , chapter-3 , Beer example servlet code :

You see there we are using the PrintWriter object (say out) and invkoing the println() method on it , then also we are sending(commiting) the response (but not using the forward method at all)


Thanks
Vishal Chugh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic