Forums Register Login

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

+Pie Number of slices to send: Send
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 ?
+Pie Number of slices to send: Send
You can use html meta tag in your response to redirect page.
<META http-equiv="refresh" content="5;URL=http://www.google.com">
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
 

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 !
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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...
this llama doesn't want your drama, he just wants this tiny ad for his mama
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4412 times.
Similar Threads
To load the data for the entire application
Thinking in 3D
Refresh problem in Servlets !!
Avoide double submit
Applet with Theme does not refresh properly
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:16:45.