Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

file download !

 
subodh varshney
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PrintWriter out1 = response.getWriter();
response.setContentType("application/octet-stream");
response.addDateHeader("Expires", 1);
response.setHeader("Content-Disposition","attachment;filename="+pagename);
out1.write(contents.substring(0,contents.length()).trim());


I m using above code it is working, but when i download file it includes some extra lines(whitespaces) in the haeder of the file
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're not doing this in a JSP, are you? Because that wouldn't work.

Also, can you guarantee that the contents will always be text, never binary? "application/octet-stream" is generally used for binary content.
 
subodh varshney
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, I m using JSP file.
content will always be text.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs generally insert additional whitespace. The best way to avoid that is to use a servlet instead.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic