Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using response.setcontenttype

 
Shreya Menon
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
If I want to see the response of my jsp as a text file in the browser, can I use response.setContenttype in jsp ?
If so, can anyone give me a piece of code ?
Maya
 
Sakti Singh
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes,
try this:
-----------
response.setContentType("text/html")
thanks
Sakti
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
response.setContentType("text/plain");
- Peter
 
Dariusz Lubaczewski
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I want to make the response of my jsp as a file on the disc, can I use response.setContenttype in jsp?
If so, what should be the code?
now I have:
response.setContentType("text/plain; charset=windows-1250");
but it takes jsp to the browser - can anyone help me?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D.L. --
Welcome to JavaRanch!
We ain't got many rules round these parts, but we do have our naming policy, which requires that your display name be a first and last name; the last name must be at least two letters and the whole name must at least sound real. Please head over here and change yours, pronto. Thanks, pardner, and hope to see ya around the Ranch!
Now, as to your post: note that if you've got a new question to ask, you oughta start a new thread. They're cheap, and it's a better way to get your question noticed than hitchin' onto somebody else's wagon.
To answer your question: if you mean that you want the response to force the browser to throw up a "save file" dialog, try using the MIME type "application/octet-stream" instead of "text/plain".
 
bj bj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello i have a problem with setContentType in JSP
i put in my Jsp file :
response.setContentType("application/pdf");
but my i.e no understand and no open the file with Acrobat Reader
anyone know that?
 
bj bj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
even if i put response.setContentType("text/html");
i.e doesn't want to open the file ?!?!
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can't just set the contenttype. You also have to make sure the generated data is really of that type or the browser will barf
 
bj bj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i use pdflib so the file is a pdf but i have a box that says that the file can broke the computer !!!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"bj bj",
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Thanks!
bear
JSP Forum Bartender
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic