Forums Register Login

Problem with sending plain text

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Didn't try that. I'll give it a try on Tuesday. Thanks!
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Heh, those wacky programmers.
Nice work-around though.
+Pie Number of slices to send: Send
And this works also:
response.setHeader("Content-Disposition","inline; filename=test.txt");
+Pie Number of slices to send: Send
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");
Skool. Stay in. Smartness. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1214 times.
Similar Threads
Default content-type
how to write color text in text file
Role of files with extension .inc
Download file HELP?
Doesn't work properly of my JNLP webstart
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:26:47.