Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem With response.sendRedirect  RSS feed

 
ch praveen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
In order to redirect the request to another page I have implemented response.sendRedirect() method. Eventhough, statements below response.sendRedirect() method are being executed.
eg:: ------------------
if(somecond) {
response.sendRedirect("somepage.jsp");
}
somestatements;
------------------
Here 'somestatements' are executed even if request is redirected to somepage.jsp. Don't say to put else, can u please suggest me a way to pass the control to another page without causing the staments below the redirection step to be executed.
 
Dora Babu k
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
response.sendRedirect("somepage.jsp");
When use sendRedirect from current page the control will go to the somepage.jsp then how can you see remaining statement(current page)? Might be not satisfying if condition.
 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've done similar code many times, and I've never run into this problem. Control should automatically be redirected to the other page, and following statements should not be executed, right?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should do a return immediately after the sendRedirect() in order to prevent the following statements from executing.
Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All sendRedirect does is to set headers in the response that cause the client to perform the redirect. It does not do any branching on its own. So if you do not "if" it, or use a return such as William suggested, the code following will most certainly be executed.
[ April 05, 2004: Message edited by: Bear Bibeault ]
 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed -- I just looked at my code and I did include an "else". This is why I never ran into this problem.
 
ch praveen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for ur replies. Now I have implemented a return statement after response.sendRediret(),
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!