How should I implement simple file download servlet?
The idea is that with the GET request index.jsp?filename=file.txt, the user can download for example. file.txt from the file servlet and the file servlet would upload that file to user.
I am able to get the file, but how can I implement file download?
That depends. If said file is publicly available via your HTTP server or servlet container you can simply redirect to via
response.sendRedirect().If it’s not, you’ll need to manually copy it to response output stream:
You’ll need to handle the appropriate exceptions, of course.