Just write first the servlet that sends the file located on the server to the user.
Then, when the user clicks the button, for example, you call the servlet with the appropriate parameter.
Here is an excerpt from our servlet implementation
response.reset(); response.setContentType("application/octet-stream"); response.setContentLength(contentLength); response.setHeader("Content-disposition", "attachment; filename=\"" + filename + "\""); output = new BufferedOutputStream(response.getOutputStream()); int data = input.read(); while (data != -1) { output.write(data); data = input.read(); } output.flush();
source share