Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Using response.setcontenttype

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes,
try this:
-----------
response.setContentType("text/html")
thanks
Sakti
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
response.setContentType("text/plain");
- Peter
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
even if i put response.setContentType("text/html");
i.e doesn't want to open the file ?!?!
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !!!
 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic