• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

file downoad [browser issue]

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm trying to download the file and it downloads successfully. But problem I'm facing when I get Download File dialog, and click on Open directly without downloading, it doesn't get opened in the IE 6.0 Windows XP SP2 and gives the error

"Cannot find the C:\Documents and Settings\<username>\Local Settings\Temporary Internet Files\Content.IE5\<session>\<filename>.txt file.

Do you want to create a new file?"

I've specified content-type and "Content-Disposition" in servlet and trying to write the data using FileOutputStream.

Now, same is not the case with Mozila. I can open and view the file without any problem..Is this anything that I've to code IE specific in Servlet when downloading the file?

-Bhavin
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't use FileOutputStream to write data to a servlet response.
 
Bhavin Sanghani
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried ServletOutputStream even but same result...If I can't use FileOutputStream then why it gets open in Mozila?

-Bhavin
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you post some code so that we can see what you're doing?
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a sample code,try for it all browsers.it will work fine.

resp.setContentType("application/download");
resp.setHeader("Content-Disposition", "attachment;filename="usercanchangeName + ".format");

OutputStream servletoutputstream = resp.getOutputStream();
byte abyte0[] = new byte[4096];
BufferedInputStream bufferedinputstream = new BufferedInputStream(new FileInputStream(new File(downloadfilenamewithformat)));
int i;
while ( (i = bufferedinputstream.read(abyte0, 0, 4096)) != -1)
servletoutputstream.write(abyte0, 0, i);

bufferedinputstream.close();
servletoutputstream.flush();
servletoutputstream.close();
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, don't close the servlet output stream. The container will do that. Second, you might try writing the data to a ByteArrayOutputStream to convert it to a byte[]. Then, you can set the contentLength of the response and I think that might clear up your issues. If IE doesn't know how long the file is, then it might not think you're done.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

"Cannot find the C:\Documents and Settings\<username>\Local Settings\Temporary Internet Files\Content.IE5\<session>\<filename>.txt file.



I've seen this happen when the browser's cache is full.
 
Bhavin Sanghani
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, when i upload the file i store directly in DB (BLOB). When I download I'm getting data in bytes that I pass to ServletOutputStream.

ServletContext context = servlet.getServletContext();
String contentType = context.getMimeType(docName);

if (contentType != null) {
response.setContentType(contentType);
} else {
response.setContentType("application/octet-stream");
}
response.setHeader("Content-Disposition", "attachement; filename=" + downloadFile + ";");
byte []data = actualData;
response.setContentLength(data.length);
OutputStream servletoutputstream = response.getOutputStream();
servletoutputstream.write(data);

within method it doesn't throw any error..but at this moment Download dialog is not popped up....and finally I end-up with one JSPException....

I want to know when this Dialog should be popped up? And above code is correct for downloading data?

-bhavin
 
Bhavin Sanghani
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, cache is not full. I've checked it...

-bhavin
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic