Reputation: 694
if(condition true){
request.sendRedirect("//Some URL");}
// Some other code
Now my question is when we redirect, the some other code will execute or not ? If execute when, before sendRedirect or after sendRedirect ?
Upvotes: 12
Views: 6280
Reputation: 1255
The sendRedirect
method does not halt the execution of your method.
You should either branch your code in such a way that the call to sendRedirect
is the last statement in your method, or explicitly call return;
after calling sendRedirect
.
See also http://www.coderanch.com/t/556146/Servlets/java/response-SendRedirect-session
Upvotes: 12
Reputation: 3829
It would be very confusing to do some stuff after redirect, so it should be the last statement of the flow. Commit, close your stuffs before redirect to help understanding your code.
Upvotes: 2