Does RequestDispatcher.forward() return to the caller ?

sampreet kaur chawla

Yes, like any Java method call, RequestDispatcher.forward() returns to the caller.

Hence we should ensure that, the caller should not be using PrintWriter() or getOutputStream() object, as it results in IllegalStateException. Neither should the call be followed by another call of RequestDispatcher.forward() or RequestDispather.include().

[The idea of RequestDispatcher.forward is that the first servlet sets things up, and the second one prints. Unfortunately, that architecture is somewhat limited. If you want both to print, you must use RequestDispatcher.include instead. -Alex]