Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Set Content Type

 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
I have read about ServletResponse class and method setContentType(String type) in Servlet API.
It say that "If obtaining a PrintWriter, this method should be called first".
Does it mean that if we use ServletOutputStream, we can use this method after and before we use method getOutputStream() ?
thanks
daniel
 
Ken Januski
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that it means that if you use PrintWriter you must call setContent first. You don't need to do so if you use a ServletOutputStream. If you're using the SCWCD book I think that part of it is a little confusing.
I say this because I had the same questions 30 minutes ago when reading it.
 
Ken Januski
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To add to what I said previously, based on Java Servlet Programming book, you need to call setContentType before calling getWriter because getWriter looks at the content type to determine which charset to use. ServletOutputStream doesn't do so.
 
Thomas Kijftenbelt
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
the scwcd exam study kit states that before calling getOutputStream, you call setContentType.
greetings,
TK
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!