Forums Register Login

Doubt on setContentType() method

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send

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
+Pie Number of slices to send: Send
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”)



  • +Pie Number of slices to send: Send
    Thanks a lot Nishan/Balu for your response.Now i am clear.
    +Pie Number of slices to send: Send
     

    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
    Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 947 times.
    Similar Threads
    Problem with JSPs in web application
    is setContentType Optional?
    HttpServletResponse& HttpServletRequest
    Session tracking with URL rewriting
    setting characters encoding
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Mar 28, 2024 11:36:25.