It's not a secret anymore!
The moose likes JSP and the fly likes Using response.setcontenttype Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » JSP
Bookmark "Using response.setcontenttype" Watch "Using response.setcontenttype" New topic

Using response.setcontenttype

Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
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 ?
Sakti Singh

Joined: Dec 13, 2000
Posts: 16
try this:
Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
- Peter
Dariusz Lubaczewski

Joined: Nov 28, 2003
Posts: 1
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?

=====<br />DaRek
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

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".

[Jess in Action][AskingGoodQuestions]
bj bj

Joined: Apr 28, 2004
Posts: 3
hello i have a problem with setContentType in JSP
i put in my Jsp file :
but my i.e no understand and no open the file with Acrobat Reader
anyone know that?
bj bj

Joined: Apr 28, 2004
Posts: 3
even if i put response.setContentType("text/html");
i.e doesn't want to open the file ?!?!
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
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

Joined: Apr 28, 2004
Posts: 3
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

Joined: Jan 10, 2002
Posts: 63202

"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.
JSP Forum Bartender

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Using response.setcontenttype
jQuery in Action, 3rd edition