• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to reload a page after commiting the response with an outputstream ?  RSS feed

 
Leinad Jan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

I'm trying to automatically reload the page that is generating a file. Is there a way to redirect it after closing the outputstream ?
 
Venkat Sadasivam
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use html meta tag in your response to redirect page.
<META http-equiv="refresh" content="5;URL=http://www.google.com">
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leinad Jan wrote:Hi everybody,

I'm trying to automatically reload the page that is generating a file. Is there a way to redirect it after closing the outputstream ?

Wait .. You're writing a file to the outputstream using JSP?? You shouldn't be doing this. Use a Servlet. Otherwise the file will be cluttered with any template text which you wrote in JSP.

Go back to the link or button which you use to download the file. Let it invoke two requests asynchronously. One to download the file and another to change the location of the current page. You can use the actual action of the link or button for the one and some piece of Javascript in the onclick attribute for the other.

E.g.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Venkat Sadasivam wrote:You can use html meta tag in your response to redirect page.
<META http-equiv="refresh" content="5;URL=http://www.google.com">

Utterly bad idea. This string will be written to the file which he is trying to stream using the JSP page or it will even generate an IllegalStateException. The response should contain nothing else than the file. As said before, you don't achieve that with JSP, but with a Servlet.
 
Leinad Jan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bauke Scholtz wrote:
Leinad Jan wrote:Hi everybody,

I'm trying to automatically reload the page that is generating a file. Is there a way to redirect it after closing the outputstream ?

Wait .. You're writing a file to the outputstream using JSP?? You shouldn't be doing this. Use a Servlet. Otherwise the file will be cluttered with any template text which you wrote in JSP.

Go back to the link or button which you use to download the file. Let it invoke two requests asynchronously. One to download the file and another to change the location of the current page. You can use the actual action of the link or button for the one and some piece of Javascript in the onclick attribute for the other.

E.g.


Hello,

no I don't use a JSP to write the CSV. It's done in an Action file. I don't need to create a servlet only for that either. I think your solution is what I'll do, asynchronous request. I'll put a timer that will call a new request, but with different parameters.

Thank you all for you help !
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's okay then. Only the part "the page that is generating the file" didn't sound very good.

Basically you should invoke two requests. One to download the file and one to navigate. You cannot send two responses back for one request. You also cannot send a response without a request.
 
Leinad Jan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bauke Scholtz wrote:That's okay then. Only the part "the page that is generating the file" didn't sound very good.

Basically you should invoke two requests. One to download the file and one to navigate. You cannot send two responses back for one request. You also cannot send a response without a request.


The solution works well on my local server, but it doesn't work at all on an external server. Maybe I should remove the confirm in javascript that ask to the user if the file has been finished. Because when the external server is slower then the delay, the confirm window appears before the the download dialog. And it only appears when the confirm is gone. And the name of the file is weird...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!