• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on setContentType() method

 
prashant k. gupta
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please clarify me about response.setContentType(), whether its required to set content type before writing in to response... or is there default method for content type if we don’t explicitly define setContentType().

In below example if we don’t set content type, as its commented for contentType , will it throw the runtime exception or it will work fine. How the content will be shown in browser.


please explain. Thanks In advance.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It is always recommended to set ContentType() to the response that you generate. It tells the browser on how to handle the incoming response data.

however if you don't set it , it will still run considering as text/html
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prashant,

No it is not mandatory required if you are not set it will take default value text/html

SetContentType() is used to intimate the browser that which type of content is coming as response,Depending upon the contentType browser treats with the response.

  • ContentType is also called as MIME(MultipurposeInternetMailExtension)type


  • Using this type we can set the response to the client or browser or useragent


  • it will give the response based upon the ContentType


  • default MIME type is(”text/html”)



  •  
    prashant k. gupta
    Ranch Hand
    Posts: 62
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks a lot Nishan/Balu for your response.Now i am clear.
     
    Harshana Dias
    Ranch Hand
    Posts: 348
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    will it throw the runtime exception or it will work fine. How the content will be shown in browser.


    it would be better if you try it by your self and see what will hapen then ask what is the reason for that behaviour you saw
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic