• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setContentType() after getWriter()

 
JohnWilliam Fitz
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

In Charles Lyons' book on p104 it says "setting the content type or encoding only has an effect before the getWriter() method is first called".

But when I test this assertion with the following code in my doGet()...



..."hi" is output to the browser AND the Content-Type header is set to "pigs/blankets" (I use IEWatch to see the incoming response headers).

Why might that be? Am I misunderstanding something?

Thanks!
John
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, this should be more explicit! It means if you set the character encoding via the setContentType method then it won't work. An example would be: "text/html;charset=UTF-8". This is because it is the character encoding which is used to set up the Writer. This also applies to the setLocale(java.util.Locale) method which can also change the character encoding. You can read more in the API documentation for these methods.

I'll add a note to myself to add this clarification to the errata. Thanks for spotting it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic