You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Denis Avdic <de...@gmail.com> on 2005/12/21 16:51:01 UTC

Redirect after a file download

Hello,

I have an application that enables a user to download a file and keeps
stats on total downloads as well as last time anyone downloaded a
file.  My problem is that the client wants the download page refreshed
after a file has been sent.

Right now I have a forward that points back to the download page
(which would reload the stats from the DB reflecting the new
download), but since I have something in the response in the download
action it doesn't seem to follow the forward after sending the file.

I am not quite sure how I should handle this.  Does anyone have an idea?

Thanks,

Denis

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Redirect after a file download

Posted by Denis Avdic <de...@gmail.com>.
I was unclear I guess.  No, the refresh happens after the action
STARTS sending the file, at the beginning of the download.

This solution works with a timeout on the second window.location.
I was hoping I could do something else, perhaps forking control or
something after the response has is sent, but I didn't think it
possible.

The file is constructed in the action so it's not really a direct path
to the file, thus the need for the timeout (so the action has some
time to construct the file and write to DB).

Thank you for your response,

Denis

On 12/21/05, Frank W. Zammetti <fz...@omnytex.com> wrote:
> Does the refresh *have* to happen only *after* the download is complete?
> If so, I suspect your SOL.
>
> However, what you can do if that isn't important is to start the download
> via Javascript, and at the same time kick off the refresh.  Do something
> like this:
>
> <a href="#" onClick="download();">Download</a>
> <script>
> function download() {
>  window.location = "path_to_file";
>  window.location = "path_to_this_page";
> }
> </script>
>
> I haven't tried this, but I *believe* the browser WILL NOT overwrite the
> current page when you point to a downloadable file.  So, the second call
> to window.location should still fire.  Since these are both atomic
> requests, you should get a download popup, and the page should refresh at
> the same time.
>
> I assume your statistics are updated when the download begins because I
> don't see how you could do otherwise.  So, I would think this would be OK.
>  You may however have to have a delay between the two location set
> calls... or, you could open the download in a new window, which should
> immediately close anyway IIRC.  Still, you may need a delay between the
> two, so maybe set up a timeout that waits a second or two before
> refreshing the page.
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> AIM: fzammetti
> Yahoo: fzammetti
> MSN: fzammetti@hotmail.com
>
> On Wed, December 21, 2005 10:51 am, Denis Avdic said:
> > Hello,
> >
> > I have an application that enables a user to download a file and keeps
> > stats on total downloads as well as last time anyone downloaded a
> > file.  My problem is that the client wants the download page refreshed
> > after a file has been sent.
> >
> > Right now I have a forward that points back to the download page
> > (which would reload the stats from the DB reflecting the new
> > download), but since I have something in the response in the download
> > action it doesn't seem to follow the forward after sending the file.
> >
> > I am not quite sure how I should handle this.  Does anyone have an idea?
> >
> > Thanks,
> >
> > Denis
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Redirect after a file download

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Does the refresh *have* to happen only *after* the download is complete? 
If so, I suspect your SOL.

However, what you can do if that isn't important is to start the download
via Javascript, and at the same time kick off the refresh.  Do something
like this:

<a href="#" onClick="download();">Download</a>
<script>
function download() {
  window.location = "path_to_file";
  window.location = "path_to_this_page";
}
</script>

I haven't tried this, but I *believe* the browser WILL NOT overwrite the
current page when you point to a downloadable file.  So, the second call
to window.location should still fire.  Since these are both atomic
requests, you should get a download popup, and the page should refresh at
the same time.

I assume your statistics are updated when the download begins because I
don't see how you could do otherwise.  So, I would think this would be OK.
 You may however have to have a delay between the two location set
calls... or, you could open the download in a new window, which should
immediately close anyway IIRC.  Still, you may need a delay between the
two, so maybe set up a timeout that waits a second or two before
refreshing the page.

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com

On Wed, December 21, 2005 10:51 am, Denis Avdic said:
> Hello,
>
> I have an application that enables a user to download a file and keeps
> stats on total downloads as well as last time anyone downloaded a
> file.  My problem is that the client wants the download page refreshed
> after a file has been sent.
>
> Right now I have a forward that points back to the download page
> (which would reload the stats from the DB reflecting the new
> download), but since I have something in the response in the download
> action it doesn't seem to follow the forward after sending the file.
>
> I am not quite sure how I should handle this.  Does anyone have an idea?
>
> Thanks,
>
> Denis
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org