I am new to Java Servlets, but would like to write files that are located on my server to a client’s file systems. For example, if the client says to write to “C:\Users\Dan\Desktop”, how can I write a file to that destination? I have a class that extends HttpServlet- if someone could point me in the right direction, I would appreciate it.
Share
The way it is done is usually to return to client a data stream that will prompt the browser to save the file. However, server can’t dictate what location file will be saved to.
To do it include
headers in your servlet response. Note that user can still overwrite your recommended file name in most browsers and location will be determined by browser (either default user download directory or whatever user will choose at the prompt).