I am trying to download a file to the client machine, the file exists in my servlet WEB-INF folder
So, in my doGet() I have something like this,
String path = "/u/my/workspace/FirstServlet/WebContent/WEB-INF/04:04:2014/logs.txt";
String result = "<a href='"+path+"' target='_blank'>Download result</a>";
request.setAttribute("ViewResult", result);
in my jsp I have,
<div>${ViewResult}</div>
but this is not downloading the file but is returning a HTTP 404 requested resource not found
even though the file is there.
So based on this answer I've tried
response.setHeader("Content-Type", "text");
response.setHeader("Content-Disposition", "attachment;filename="+path);
though it has downloaded a file, the contents of the file are same as my jsp page source code.
How to do this right?