Wednesday 28 February 2007

Sending files to browser in JSP

Sending files to browser in JSP

<%
// fetch the file
String filename = "companySecret.txt";
String filepath = "C:\\";

response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + '"');

java.io.FileInputStream fileInputStream = new java.io.FileInputStream(filepath + filename);

int i;
while ((i=fileInputStream.read()) != -1)
{
out.write(i);
}

fileInputStream.close();
out.close();
%>



Community discussing C and its derivatives like Win32, C++, MFC, C# tutorials - www.cfanatic.com

No comments: