• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with sending plain text

 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to send a plain text document (don't ask why) to the browser from a servlet. I set the content type to text/plain but it always prompts me to save the file. Shouldn't plain text just display in the browser window?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, should do. Have you tried setting the filename to so it has a .txt extension?
response.setHeader("Content-Disposition","attachment; filename=test.txt");

Sometimes it make a difference though, based on browsers trying to be too intelligent with incomming file types.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Didn't try that. I'll give it a try on Tuesday. Thanks!
 
Louise Haydu
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This link may shed some light...
http://ppewww.ph.gla.ac.uk/~flavell/www/content-type.html
It also mentions the *.txt extension, as recommended by David above.
[ September 01, 2002: Message edited by: Louise Haydu ]
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hate IE!!!
OK, I found the problem and the cure...
It seems that if the text file is too big (not sure what "too big" is yet) then IE will not display it in the browser even if you identify it as a text file. But there is a workaround. I send a single new line character and then flush. Then I send the rest of the file. It seems that receiving the single character commits IE to displaying as text.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heh, those wacky programmers.
Nice work-around though.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And this works also:
response.setHeader("Content-Disposition","inline; filename=test.txt");
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After all that, the users changed their minds and decided they would prefer to be prompted to save the file. This works to do that in IE:
response.setHeader("Content-Disposition","attachment; filename=test.txt");
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic