I have a java bean which I use to download files from the server.
public void download(String filePath) throws IOException {
try {
String fn = new File(filePath).getName();
byte[] data = grabFile(filePath);
XspHttpServletResponse response = (XspHttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
response.setContentType(URLConnection.guessContentTypeFromName(fn));
response.setHeader("Content-disposition", "attachment; filename=" + fn);
OutputStream output = response.getOutputStream();
output.write(data);
output.close();
}catch(Exception e) {
}finally {
FacesContext.getCurrentInstance().responseComplete();
}
}
I can call this bean from a link on my xpage using the following SSJS code, I am using full refresh in the link.
var dw = new FileShare();
dw.download("c:\test\filename.docx")
The code works fine, the file is downloaded from the server at the location when I click the link but it only works the first time. If I reload the whole page using the browser refresh button I can download another file.
How can I fix this code so that I can click to download from all links I have on my xpage without reloading the browser.