Question

I am confused on how to do this.. Currently I am implementing an automatic download using Javascript:

target.appendJavaScript("location.href='"+ "./Access.xls" + "';");

This doesn't work.. What is the proper way to trigger an automatic download and how do I properly set the url? I am not too familiar with Javascript but trying to implement this. The file is in the root of the project.. but it tells me it is not found.

Also, when the user downloads it, I would like to then delete it right away after it is downloaded using Javascript, how can I do this? I am using Javascript because I am calling this file within an ajax method.

Thanks!

Was it helpful?

Solution

The best way to get access to that resource, you should use a ResourceReference as explained here. To get the url of a ResourceReference use:

RequestCycle#urlFor(ResourceReference, PageParameters)

However, I don't understand what you need regarding deletion of the file once downloaded. If your file is contained in the jar/war of your project, I don't believe it can be deleted from inside the web app. You could block access to it once it's downloaded however, if that makes sense. Not sure what you're trying to achieve here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top