Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setContentType

 
anand phulwani
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ranchers,

What if i dont write response.setContentType("text/html");
in the doPost() method,
and is this method used in doGet() method,and if not why so.
 
Martyn Clark
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
you use the setContentType in either method when you are sending the response, if you don't set it the client will not know what you are sending. Say you was sending a pdf file, the right way is to let the cient know about this.
 
anand phulwani
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply martyn,

but will that invoke an exception if i send without setting the content type or does it take "text/html" by default.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You won't get an exception.

It's up to the browser to interprete the response whose content type has not been set. So instead of leaving the browser guess, it's better to set the content type explicitly, to avoid unpredictable behaviour.

http://ppewww.ph.gla.ac.uk/~flavell/www/content-type.html
 
anand phulwani
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Satou,
That Helps Me Clear My Doubt.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic