So the answer is no right? I am convinced that the req, res cycle is different in sendRedirect and dispatcher.forwardTo.
if the
[code:] sysout("I am in caller servlet A");
redirection code;
sysout("I am back in A");
[:code]
The second line "I am back in A" will work only in case of dispatcher and not redirect.
Am I correct now?
in Mkumar
Greenhorn
Joined: Sep 08, 2008
Posts: 20
posted
0
You can back from Servlet B to Servlet A, but request will be new one not the same request object.
-Manoj
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
1
posted
0
The second line "I am back in A" will work only in case of dispatcher and not redirect.
Nope
Think about the request Thread of execution.
The sendRedirect causes the sending of a response back to the client, but the Thread continues executing in the original servlet. Since the response has been sent, you cant write anymore to the client.
The Thread can write to a log or clean up resources, but generally, you should just return.
By returning from the doGet or doPost you return control to the servlet container.
In the meantime the client has generated a new request to the redirected URL - that gets a completely different Thread.
Bill
tarun saha
Greenhorn
Joined: Mar 23, 2010
Posts: 27
posted
0
ok guys, now i got it.
since finally is there in the jvm stack, it has to be executed anyway unless i shut down jvm using System.exit();
but the main thing is that once the redirection takes place the request response cycle will be different and the old request/ response will not be available.