• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How does server side forwarding exactly work?

 
Vikrant Pandit
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When we call RequestDispatcher.forward, what happens when the method returns?
 
Senthil Kumar
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pandey,
I guess that the forward doesn't return to the calling servlet.It just
transfers the control to the called resource.
when we foward it just looks at the web.xml and does everythingelse as it would do in normal scenario.

hope this helps,
 
Vikrant Pandit
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But isn't a normal java method supposed to return ???
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Just trying to explain the steps :

1. You aquire the resource when you call the getRequestDispatcher of request or context, using the URL.
2. If this is succeded , then the path attribues are added to the request and then the container call the service method of the target resource, as effect of forward method, using the request and response parameters passed to forward method.
3. After completion of the service method of the target resource, the control is back to the calling servlet. ( assuming there are no errors).
4. Code after the forward method call are excuted, but at this stage the response output object is in commited state, and you can not write anything to the response. But Still you can execute other codes.

Hope this help

Thanks
 
Senthil Kumar
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
yeah Vivek Narendra was right.The code after the forward() still runs.Only you can't write anything(i.e i mean flush()ing ) into response object after your forward() call.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic