This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have written the following code to download a file from a MySql database using a Servlet.The problem i have is that i havnt done it right. Can someone please point me in the right direction. Any help will be greatly appreciated. Thank you for your help.
// Set the content type to the byte-stream type (since we don't know it)
// see http://en.wikipedia.org/wiki/MIME_type for meaning of MIME type
// Set header: allows us to specify the download filename to the browser
// see http://en.wikipedia.org/wiki/List_of_HTTP_headers for header types
response.setHeader("Content-Disposition", "attachment; filename=" + new File(fileName).getName());
ServletOutputStream out = response.getOutputStream();
// Now copy requested file to the response output stream
// prefix filename with location of our files
FileInputStream f = new FileInputStream(fileName);
int nextByte = f.read();
// note: there is a faster way to do this using alternative read() methods