Go4Expert

Go4Expert (http://www.go4expert.com/)
-   JSP (http://www.go4expert.com/articles/jsp-tutorials/)
-   -   Sending Files To Browser in JSP (http://www.go4expert.com/articles/sending-files-browser-jsp-t3094/)

pradeep 21Feb2007 15:42

Sending Files To Browser in JSP
 
Code: 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();
%>


parvez.yu 6Mar2008 17:04

Re: Sending Files To Browser in JSP
 
ok got it

gkumar 27Jun2009 15:55

Re: Sending Files To Browser in JSP
 
Hi,
I think it is a stupid problem. But I do not know how it can be cracked:
I want need the user to be able to download a file that is stored somewhere in the server.
I found some solutions like:
http://wiki.apache.org/myfaces/Sending_Files
If I integrate this code in my action or actionListener method it does not works.
The reason is that the result for the response
HttpServletResponse response =
( HttpServletResponse ) context.getExternalContext().getResponse();
is always null.
Have anyone a tip?
Thanks


All times are GMT +5.5. The time now is 10:08.