• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sequentially to send response.reDirect()

 
visu bikkina
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I given in my servlet.
reponse.sendRedirect("setup.exe");
reponse.sendRedirect("http://www.yahoo.com");
it is executing second statement ignoring the first one.
but i want to download first the exe file and then it has to redirect to http://www.yahoo.com.
please help me regarding this.
thanks in advance
regards,
Visu bikkina

 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by visu bikkina:
I given in my servlet.
reponse.sendRedirect("setup.exe");
reponse.sendRedirect("http://www.yahoo.com");
it is executing second statement ignoring the first one.

If that is the case, your server appears to be in violation of the servlet spec. According to v2.2 of the spec, section 6.3, sendRedirect should do the following:
1. Clear the data in the response buffer.
2. Set the response headers that tell the client browser to redirect to the given URL.
3. Commit the response.
From your description, it appears that 3. is not happening. Your second sendRedirect should have thrown an IllegalStateException because the response had already been committed. Instead of this, the sendRedirect is accepted and overwrites the first redirection.

but i want to download first the exe file and then it has to redirect to http://www.yahoo.com.

As you may have gathered from the description above, it won't work this way. You cannot queue instructions (responses) to the browser. The initiative needs to be at the browser end -- you can probably use JavaScript to do it, open a window for the download then redirect to yahoo, I'm not entirely sure.
- Peter
 
Mike Nightsky
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sendRedirect is not an instant exit from this method.
you have to put a return after the sendRedirect.
And the seconde sendredirect overrides the first one.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Nightsky:
sendRedirect is not an instant exit from this method.
you have to put a return after the sendRedirect.
And the seconde sendredirect overrides the first one.


Your first point is true, but the first sendRedirect should close (commit) the response which, as Peter said, should cause an illegal state exception.

I'm curious, which container (server) are you using?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doc says:

sendRedirect() throws java.lang.IllegalStateException - If the response was committed or if a partial URL is given and cannot be converted into a valid URL

cheers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic