aspose file tools*
The moose likes Servlets and the fly likes Default content-type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Default content-type" Watch "Default content-type" New topic
Author

Default content-type

Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
Is the default content-type "text/html" for servlet response?


SCJP 5.0 | SCWCD 1.4 <br /> <br />If you don't know where you are going, any road will take you there!
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Answer is Yes.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
Yes it is text/html unless specified explicitly using setContentType(String str) method before writing the message to response object.


~Sanjeev Singh<br />SCJP 1.5
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
I thought it was text/plain for servlets.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

setContentType() JavaDoc
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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:



Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
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
Bartender

Joined: Oct 14, 2005
Posts: 18987
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Default content-type