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 ");