File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes setting/not setting content-type header Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "setting/not setting content-type header" Watch "setting/not setting content-type header" New topic
Author

setting/not setting content-type header

Erin Li
Greenhorn

Joined: Mar 07, 2010
Posts: 5
Hi,
I read here that content-type's default for servlets is text/plain.
Is that correct? I'm using firebug to see the response header. I didn't set any content-type in my servlet. I got this response header in firebug:

Response Headers
Server Apache-Coyote/1.1
Content-Length 27
Date Sun, 07 Mar 2010 17:13:04 GMT


Thanks
Erin
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

There is no explicit default -- if you don't set one, there won't be one.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Erin Li
Greenhorn

Joined: Mar 07, 2010
Posts: 5
Thanks Bear for the reply.
One additional question! what would be the side effects on the browser for not setting any content-type?

Regards
Erin
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
Erin Li wrote:Thanks Bear for the reply.
One additional question! what would be the side effects on the browser for not setting any content-type?

Regards
Erin

Then the browser has to guess what to do with the content. Will all browsers guess correctly?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Browsers maintain a map of how to deal with MIME types of the content sent to them. If they need to guess, they'll probably use a number of techniques to determine the MIME type, the most visible of which will be examining the URL for file types. It's a safe bet that all browsers will deal with content whose URL.s end with .html or .txt correctly.

In a servlet environment where URLs are mappings rather than references to physical files with file types, most browsers will simply assume a universal default of text/html.
Erin Li
Greenhorn

Joined: Mar 07, 2010
Posts: 5
Thanks Bear/Mark it really helps.
 
GeeCON Prague 2014
 
subject: setting/not setting content-type header