• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Doubt on setContentType() method

 
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.
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • 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
 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • 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.
     
    Ranch Hand
    Posts: 352
    • 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
     
    Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
    Devious Experiments for a Truly Passive Greenhouse!
    https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
      Bookmark Topic Watch Topic
    • New Topic