About Question com.enthuware.ets.scwcd.v5.2.390 :

Moderator: admin

Post Reply
ETS User

About Question com.enthuware.ets.scwcd.v5.2.390 :

Post by ETS User »

Which of the following statements is correct regarding a RequestDispatcher object?

a>A call to forward() clears the output buffer before the target resource is invoked.
b>The execution control returns to the resource that has called the forward() method after the callee resource finishes processing.
c>It is not advisable for the forwarding resource to produce any output.

all the 3 options above are marked as correct. But I am pretty not sure how is option"b" correct. Ideally in forward the control does not return back to the forwarding page. Isnt this the difference between the include and forward mechanisms?

admin
Site Admin
Posts: 10078
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scwcd.v5.2.390 :

Post by admin »

The call to forward is a regular method call. After that method finishes, the execution control will return to the caller. For example, when method a calls method b, the execution control will return to a after b is finished.

Code: Select all

void a(){
  System.out.println("before");
   b();
  System.out.println("after");
}

void b(){
}
That is why b is correct.

Of course, if you try to write further to the response after the call returns from forward(), you will get an exception but that is because of the way servlet API has been designed and has nothing to do with java language semantics, which are still the same.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests