Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

file download !  RSS feed

 
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: 42970
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: 42970
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!