• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Query on response.sendRedirect() ???

 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Why it is so the any line of code which is there after a response.sendRedirect() method gets executed ?

As we know that incase of sendRedirect() controls is send back to browser. I have written a servlet in which after sendRedirect() method there is one System.out.println statement but after redirect to my jsp page that println statement executed.

Now my confusion is if control goes to my jsp page then how that println statement can execute after sendRedirect() ?

Thanks & Regards
Bikash
[ June 07, 2004: Message edited by: Bikash Paul ]
 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is because the response has not been committed. After using this method, the response should be considered to be committed and should not be written to. Just type
return; after this method.
 
Bikash Paul
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

First of all thanks for the reply. But my question is after using this method, the response should be considered to be committed then why it is executing println statement. I know that using return; I can commit response.
Can any one please tell me what will be probable reason behind that ?

Thanks & Regards
Bikash
 
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sendRedirect does not contain any magic that alters the stream of execution of the code. All it does is to set response headers appropriately so that when the response is sent to the browser, it will perform the redirect.

It is up to you to not do anything illegal after you perform this operation.
 
Destroy anything that stands in your way. Except this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic