Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDipatcher

 
Atul Sawant
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,

Are the following statements correct?

The execution control returns to the resource that has called the forward() method after the callee resource finishes processing.
RequestDispatcher.forward() is also a normal method call, so the control does return to the calling resource.

I thought only include() method does that, it returns the servlet and does the rest of the process.

Kindly provide your inputs.
 
Rancy Chadha
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Atul,

Both include and forward calls by request dispatcher return to the calling servlet but the basic difference is that, before the forward method of the RequestDispatcher interface returns, the response content must be sent and committed, and closed by the servlet container (SRV 8.4) whereas in case of include it is not so. Therefore after forward return you cannot write anything to the output stream since it is already closed however you can do so using include.
 
Srinivasan thoyyeti
Ranch Hand
Posts: 557
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rancy,

I would like to know...

After executing forward and getting back control
what actually the servlet can do (or) supposed to do?
[ May 16, 2007: Message edited by: Srinivasan thoyyeti ]
 
Rancy Chadha
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Srinivasan,
After executing forward and getting back control
what actually the servlet can do (or) supposed to do?

I don't think calling servlet is supposed to do anything compulsarily after the forward call returns. But what it can do is, write to logs, write to console, set context attributes.
 
Srinivasan thoyyeti
Ranch Hand
Posts: 557
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rancy,

Thank you.
 
Atul Sawant
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rancy!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic