| Author |
How does server side forwarding exactly work?
|
Vikrant Pandit
Ranch Hand
Joined: Mar 27, 2006
Posts: 245
|
|
|
When we call RequestDispatcher.forward, what happens when the method returns?
|
Vikrant Pandit
|
 |
Senthil Kumar
Ranch Hand
Joined: Mar 13, 2006
Posts: 264
|
|
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,
|
when you really want something, all the universe always conspires in your favour.<br /> <br />SCJP1.5-77%<br />SCWCD-89%
|
 |
Vikrant Pandit
Ranch Hand
Joined: Mar 27, 2006
Posts: 245
|
|
|
But isn't a normal java method supposed to return ???
|
 |
Narendra Dhande
Ranch Hand
Joined: Dec 04, 2004
Posts: 950
|
|
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
|
Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
|
 |
Senthil Kumar
Ranch Hand
Joined: Mar 13, 2006
Posts: 264
|
|
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.
|
 |
 |
|
|
subject: How does server side forwarding exactly work?
|
|
|