wood burning stoves 2.0*
The moose likes Java in General and the fly likes Download file without getting a Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Download file without getting a "File Download" prompt from IE. " Watch "Download file without getting a "File Download" prompt from IE. " New topic
Author

Download file without getting a "File Download" prompt from IE.

Mike Howell
Greenhorn

Joined: Oct 22, 2004
Posts: 1
I have some java code in a servlet that generates an "xyz file" an sends it to the browser. I want IE to open the file in the associated application without prompting for a file download. (IE 6 on Windows XP)

In Windows Explorer I went under - Tools - Folder Options - File Types - scroll down until you find xyz (the extension) - highlight it - Advanced - remove the check in Confirm after Download.

From what I have seen on the web this should work, but the "File Download" dialog box still pops up. I think this is because I am sending the file outside of the response stream. I am doing this so that I don't need to create an actual file that would need to be deleted.

Does anyone have a clever solution to get a file to open on a client PC in the default app without seeing the "File Download" prompt?

Here is a sample of the code generating the file in case that is what the problem is.



private void xyzReport(

javax.servlet.http.HttpServletRequest request,

javax.servlet.http.HttpServletResponse response)

throws IOException, ServletException

{

response.setContentType("application/octet-stream xyz");

//cvs file in this case

response.addHeader("Content-Disposition", "attachment;filename=\"report.xyz\";");



PrintWriter out = response.getWriter();

out.println("TEXT FILE Generated by servlet");

ActivityReportValue activityReportValue = null;

Vector itemActivity = null;

for (int i = 0; i < 100; i++)

{

String line = ("text,text,text,text,text");

out.println(line);

}

}
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Make sure you set the correct content type, and set it to one which IE recognises as belonging to an application which can work inside the browser (like Excel or Acrobat reader).
You may also have to make sure the filetype ends in the default extension for this filetype (used to need to set the servlet name to something.xls when sending CSV data to be opened by Excel in IE4, might no longer be needed).


42
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Download file without getting a "File Download" prompt from IE.