Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Default content-type

 
Aniket Patil
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the default content-type "text/html" for servlet response?
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer is Yes.
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is text/html unless specified explicitly using setContentType(String str) method before writing the message to response object.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought it was text/plain for servlets.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't a default.
If you don't set a content type, no content type header will be sent.

The LiveHTTPHeaders pluging for Firefox is a great tool to use if you want to see this for yourself.

I just commented out the line with setContentType in a simple Hello, World servlet and ran it.
Here are the response headers:

 
Aniket Patil
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben,

Exactly my thoughts, i remember reading that there isn't a default, needed confirmation.

Would be intersted to know how the browser assumes it to be "text/html" when no content-type is set? Is this the default for a browser?
[ January 14, 2007: Message edited by: Aniket Patil ]
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Aniket Patil:
Would be intersted to know how the browser assumes it to be "text/html" when no content-type is set? Is this the default for a browser?
If you want to know why a browser will assume text/html if no content type is set, that's naturally because browsers are mostly used to display HTML pages, so it's a pretty good bet. If you want to know how, well it's an if-statement that you could probably imagine quite easily.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic