Functions and parameters of Response. setContentType ()

Source: Internet
Author: User

Response. setContentType (MIME_TYPE) is used to differentiate different types of data in the client browser. Based on the MIME_TYPE, different program embedding modules in the browser are called to process the corresponding data.

For example, the WEB browser uses the MIME_TYPE to determine whether the file is a GIF image or a JSON string.

The MIME_TYPE is fully defined in the Tomcat installation directory \ conf \ web. xml. The type in the XML node is mime-mapping.

Common types include:

Text/html

Text/htm

Text/css

Image/bmp

Image/gif

Image/jpeg

Text/plain

Text/javascript

Video/mp4

Video/mpeg

Application/pdf

Image/png

Application/rtf

Application/zip

The Response. setContentType () method is used to set the content type sent to the client. At this time, the Response content has not been returned to the client browser. The given content type can include a description of character encoding, for example: text/html: charset = UTF-8, if this method is called before the getWriter () method is called, then, the response encoding will only be set from the given content type. If the getWriter () method is called, the response character encoding is not set.

You can only set the Content-type object header in HTTP. In Servlet, it is customary to first set the request and response content types and encoding methods:

Response. setContentType ("text/html; charset = UTF-8 ");

Request. setCharacterEncoding ("UTF-8 ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.