• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Problem in downloading file from Servlet

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to download a file from server. The open/save dialog window is coming. But, if I click either save or open, in both cases, I got a Explorer error - Internet Explorer can not download <filename> from <servername>

I am using IE 6.0 with SP1

My code goes as follows:

response.setContentType("application/octet-stream");
//response.setContentType("application/download"); // I tried by adding this line and removing both (above) lines ...

response.setHeader("Content-Disposition", "attachment;filename=\"" + strFileName + "\"");
OutputStream servletoutputstream = response.getOutputStream();
byte abyte0[] = new byte[4096];
BufferedInputStream bufferedinputstream = new BufferedInputStream(new FileInputStream(new File(strFileName )));
int i;
while((i = bufferedinputstream.read(abyte0, 0, 4096)) != -1)
servletoutputstream.write(abyte0, 0, i);

bufferedinputstream.close();
servletoutputstream.flush();
servletoutputstream.close();

Anything wrong in my code???
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic