The role of Response.setcontenttype (MIME) is to enable the client browser to differentiate between different kinds of data and to process the corresponding data according to different programs embedded in different MIME call browsers.
For example, a Web browser uses MIME types to determine whether a file is a GIF image. Handles JSON strings through MIME types.
There are a number of MIME types defined in the Tomcat installation directory \conf\web.xml, which you can refer to.
Response.setcontenttype ("text/html; Charset=utf-8 "); Html
. setContentType ("Text/plain; Charset=utf-8 "); Text
Text/javascript JSON data
Application/xml XML data
This method sets the content type of the response sent to the client, at which time the response has not yet been submitted. The given content type can include a character encoding description, for example: Text/html;charset=utf-8. If the method is invoked before the Getwriter () method is invoked, the character encoding of the response is set only from the given content type. If the method is invoked after the Getwriter () method is invoked or after being committed, the character encoding of the response is not set, and in the case of using the HTTP protocol, the method sets the Content-type entity header.
Typically in a servlet, it is customary to set the content type and encoding of the request and response first:
Copy Code code as follows:
Response.setcontenttype ("Text/html;charset=utf-8");
Request.setcharacterencoding ("UTF-8");
string parameter and corresponding type of response.setcontenttype ()
<option value= "Image/bmp" >BMP</option>
<option value= "Image/gif" >GIF</option>
<option value= "Image/jpeg" >JPEG</option>
<option value= "Image/tiff" >TIFF</option>
<option value= "IMAGE/X-DCX" >DCX</option>
<option value= "IMAGE/X-PCX" >PCX</option>
<option value= "text/html" >HTML</option>
<option value= "Text/plain" >TXT</option>
<option value= "Text/xml" >XML</option>
<option value= "Application/afp" >AFP</option>
<option value= "Application/pdf" >PDF</option>
<option value= "Application/rtf" >RTF</option>
<option value= "Application/msword" >MSWORD</option>
<option value= "Application/vnd.ms-excel" >MSEXCEL</option>
<option value= "Application/vnd.ms-powerpoint" >MSPOWERPOINT</option>
<option value= "application/wordperfect5.1" >WORDPERFECT</option>
<option value= "Application/vnd.lotus-wordpro" >WORDPRO</option>
<option value= "Application/vnd.visio" >VISIO</option>
<option value= "Application/vnd.framemaker" >FRAMEMAKER</option>
<option value= "Application/vnd.lotus-1-2-3" >LOTUS123</option>
The MIME mapping strategy is which application (ie plug-in) is used in the Web page and which file is opened. There is also a problem with permissions. For example, for PDF documents, use the "application/pdf" strategy. This is common in Dynamic Web pages. There are two scenarios in which you can use an application to open a document that it cannot open, such as "Application/pdf" with "DWG" documents defined in the label, and a problem that cannot be opened. The second is that the file name extension meets the requirements, but the file content (format) does not meet the requirements. You can check the source code of the Web page you are browsing and get the error message. The check method is: View-source file. Looking for a string similar to "Application/pdf", you can see whether the file you want to open matches the application. Questioning how to resolve answers if not matched this is usually changed by the page writer. For example: You can find the HTML tag of the file you want to open in the source file, and add the application to it. For example, you would open a PDF document on a Web page, find the line in the PDF document, and add Type= "Application/pdf" to the HTML tag. For example, the following HTML file: <!----------test MIME----------->-------------------------------------------------------------------------------------------------------------
Parameter description of Response.setcontenttype ()
Copy Code code as follows:
<meta http-equiv= "Content-type" content= "text/html; CHARSET=GBK ">
Response.setcontenttype ();
* = Application/octet-stream
.001 = application/x-001
. application/x-301 =
.323 = text/h323
.906 = application/x-906
.907 = drawing/907
. A11 = Application/x-a11
. ACP = AUDIO/X-MEI-AAC
. Ai = Application/postscript
. AIF = Audio/aiff
. aifc = Audio/aiff
. AIFF = Audio/aiff
. Anv = Application/x-anv
. Asa = Text/asa
. asf = VIDEO/X-MS-ASF
. asp = text/asp
. asx = VIDEO/X-MS-ASF
. au = Audio/basic
. avi = Video/avi
. AWF = Application/vnd.adobe.workflow
. biz = Text/xml
. bmp = Application/x-bmp
. bot = Application/x-bot
. c4t = application/x-c4t
. C90 = Application/x-c90
. Cal = Application/x-cals
. cat = Application/vnd.ms-pki.seccat
. CDF = APPLICATION/X-NETCDF
. CDR = Application/x-cdr
. Cel = Application/x-cel
. cer = Application/x-x509-ca-cert
. CG4 = Application/x-g4
. CGM = APPLICATION/X-CGM
. cit = application/x-cit
. class = java/*
. CML = text/xml: Client browsers parse documents in XML format
. CMP = application/x-cmp
. CMX = APPLICATION/X-CMX
. Cot = Application/x-cot
. CRL = APPLICATION/PKIX-CRL
. CRT = Application/x-x509-ca-cert
. CSI = APPLICATION/X-CSI
. CSS = text/css: Client browsers parse documents in CSS format
. Cut = Application/x-cut
. dbf = application/x-dbf
. dbm = application/x-dbm
. dbx = Application/x-dbx
. DCD = text/xml: Client browser parses documents in XML format
. DCX = APPLICATION/X-DCX
. Der = Application/x-x509-ca-cert
. DGN = APPLICATION/X-DGN
. DIB = Application/x-dib
. dll = Application/x-msdownload
. doc = Application/msword
. dot = Application/msword
. DRW = APPLICATION/X-DRW
. DTD = text/xml: client browser parses documents in XML format
. DWF = MODEL/VND.DWF
. DWF = APPLICATION/X-DWF
. dwg = APPLICATION/X-DWG
. DXB = APPLICATION/X-DXB
. DXF = APPLICATION/X-DXF
. edn = Application/vnd.adobe.edn
. EMF = application/x-emf
. eml = message/rfc822
. ent = text/xml: Client browser parses documents in XML format
. Epi = Application/x-epi
. EPS = Application/x-ps
. EPS = Application/postscript
. ETD = APPLICATION/X-EBX
. exe = Application/x-msdownload
. Fax = Image/fax
. FDF = APPLICATION/VND.FDF
. Fif = Application/fractals
. FO = text/xml: client browser parses documents in XML format
. frm = application/x-frm
. g4 = Application/x-g4
. GBR = APPLICATION/X-GBR
. GCD = APPLICATION/X-GCD
. gif = Image/gif
. GL2 = APPLICATION/X-GL2
. GP4 = APPLICATION/X-GP4
. Hgl = Application/x-hgl
. HMR = APPLICATION/X-HMR
. HPG = APPLICATION/X-HPGL
. HPL = APPLICATION/X-HPL
. hqx = application/mac-binhex40
. HRF = APPLICATION/X-HRF
. HTA = Application/hta
. HTC = Text/x-component
. htm = text/html: Client browsers parse documents in hypertext format
. html = text/html: Client browsers parse documents in hypertext format
. htt = text/webviewhtml
. HTX = text/html: Client browsers parse documents in hypertext format
. ICB = APPLICATION/X-ICB
. ico = Image/x-icon
. ico = Application/x-ico
. IFF = Application/x-iff
. ig4 = Application/x-g4
. IGs = Application/x-igs
. III = Application/x-iphone
. img = application/x-img
. ins = Application/x-internet-signup
. ISP = Application/x-internet-signup
. IVF = VIDEO/X-IVF
. Java = java/*
. jfif = Image/jpeg
. JPE = Image/jpeg
. JPE = Application/x-jpe
. jpeg = Image/jpeg
. jpg = Image/jpeg
. jpg = application/x-jpg
. js = Application/x-javascript
. JSP = text/html: client browser parse document in hypertext format
. LA1 = Audio/x-liquid-file
. Lar = Application/x-laplayer-reg
. Latex = Application/x-latex
. LAVs = Audio/x-liquid-secure
. LBM = APPLICATION/X-LBM
. LMSFF = Audio/x-la-lms
. ls = Application/x-javascript
. Ltr = application/x-ltr
. m1v = Video/x-mpeg
. m2v = Video/x-mpeg
. m3u = Audio/mpegurl
. m4e = VIDEO/MPEG4
. Mac = Application/x-mac
. man = Application/x-troff-man
. Math = Text/xml
. mdb = application/msaccess
. mdb = Application/x-mdb
. MFP = Application/x-shockwave-flash
. mht = message/rfc822
. MHTML = message/rfc822
. MI = Application/x-mi
. mid = Audio/mid
. MIDI = Audio/mid
. mil = Application/x-mil
. MML = Text/xml
. MND = Audio/x-musicnet-download
. MNS = Audio/x-musicnet-stream
. Mocha = Application/x-javascript
. Movie = Video/x-sgi-movie
. MP1 = Audio/mp1
. MP2 = AUDIO/MP2
. MP2V = Video/mpeg
. mp3 = Audio/mp3
. mp4 = VIDEO/MPEG4
. MPA = Video/x-mpg
. MPD = Application/vnd.ms-project
. MPE = Video/x-mpeg
. MPEG = Video/mpg
. mpg = Video/mpg
. MPGA = Audio/rn-mpeg
. MPP = Application/vnd.ms-project
. MPs = Video/x-mpeg
. MPT = Application/vnd.ms-project
. MPV = Video/mpg
. Mpv2 = Video/mpeg
. MPW = Application/vnd.ms-project
. MPX = Application/vnd.ms-project
. MTX = Text/xml
. MXP = APPLICATION/X-MMXP
. NET = Image/pnetvue
. NRF = APPLICATION/X-NRF
. NWS = message/rfc822
. odc = TEXT/X-MS-ODC
. Out = Application/x-out
. P10 = Application/pkcs10
. P12 = application/x-pkcs12
. p7b = Application/x-pkcs7-certificates
. p7c = Application/pkcs7-mime
. p7m = Application/pkcs7-mime
. p7r = Application/x-pkcs7-certreqresp
. p7s = Application/pkcs7-signature
. PC5 = APPLICATION/X-PC5
. PCI = Application/x-pci
. PCL = APPLICATION/X-PCL
. pcx = application/x-pcx
. pdf = application/pdf: Client browser parses documents in PDF format
. pdf = Application/pdf
. PDX = Application/vnd.adobe.pdx
. PFX = APPLICATION/X-PKCS12
. PGL = APPLICATION/X-PGL
. pic = Application/x-pic
. Pko = Application/vnd.ms-pki.pko
. pl = Application/x-perl
. PLG = text/html
. pls = Audio/scpls
. PLT = Application/x-plt
. png = Image/png
. png = Application/x-png
. pot = Application/vnd.ms-powerpoint
. PPA = Application/vnd.ms-powerpoint
. ppm = application/x-ppm
. PPS = Application/vnd.ms-powerpoint
. ppt = Application/vnd.ms-powerpoint
. ppt = Application/x-ppt
. PR = APPLICATION/X-PR
. PRF = Application/pics-rules
. PRN = Application/x-prn
. PRT = Application/x-prt
. PS = Application/x-ps
. PS = Application/postscript
. PTN = APPLICATION/X-PTN
. pwz = Application/vnd.ms-powerpoint
. r3t = Text/vnd.rn-realtext3d
. RA = Audio/vnd.rn-realaudio
. Ram = Audio/x-pn-realaudio
. RAS = Application/x-ras
. Rat = Application/rat-file
. RDF = Text/xml
. Rec = application/vnd.rn-recording
. Red = application/x-red
. RGB = Application/x-rgb
. RJs = Application/vnd.rn-realsystem-rjs
. RJT = Application/vnd.rn-realsystem-rjt
. RLC = APPLICATION/X-RLC
. RLE = Application/x-rle
. RM = Application/vnd.rn-realmedia
. RMF = APPLICATION/VND.ADOBE.RMF
. RMI = Audio/mid
. RMJ = APPLICATION/VND.RN-REALSYSTEM-RMJ
. RMM = Audio/x-pn-realaudio
. RMP = Application/vnd.rn-rn_music_package
. RMS = Application/vnd.rn-realmedia-secure
. rmvb = APPLICATION/VND.RN-REALMEDIA-VBR
. RMX = APPLICATION/VND.RN-REALSYSTEM-RMX
. RNX = Application/vnd.rn-realplayer
. RP = Image/vnd.rn-realpix
. RPM = Audio/x-pn-realaudio-plugin
. RSML = APPLICATION/VND.RN-RSML
. RT = Text/vnd.rn-realtext
. rtf = Application/msword
. rtf = Application/x-rtf
. RV = Video/vnd.rn-realvideo
. Sam = Application/x-sam
. Sat = Application/x-sat
. SDP = APPLICATION/SDP
. SDW = Application/x-sdw
. sit = Application/x-stuffit
. SLB = APPLICATION/X-SLB
. SLD = APPLICATION/X-SLD
. SLK = drawing/x-slk
. SMI = Application/smil
. smil = Application/smil
. SMK = APPLICATION/X-SMK
. snd = Audio/basic
. Sol = Text/plain
. Sor = Text/plain
. SPC = Application/x-pkcs7-certificates
. SPL = Application/futuresplash
. SPP = Text/xml
. SSM = Application/streamingmedia
. SST = Application/vnd.ms-pki.certstore
. STL = Application/vnd.ms-pki.stl
. stm = text/html
. sty = Application/x-sty
. svg = Text/xml
. swf = Application/x-shockwave-flash: Client browser parses documents in Flash format
. TDF = APPLICATION/X-TDF
. TG4 = APPLICATION/X-TG4
. TGA = Application/x-tga
. tif = Image/tiff
. tif = Application/x-tif
. TIFF = Image/tiff
. TLD = Text/xml
. top = Drawing/x-top
. torrent = Application/x-bittorrent
. TSD = Text/xml
. txt = text/plain: client browser parses documents in plain text format
. UIn = Application/x-icq
. ULS = Text/iuls
. VCF = Text/x-vcard
. VDA = Application/x-vda
. VDX = Application/vnd.visio
. VML = Text/xml
. VPG = application/x-vpeg005
. VSD = Application/vnd.visio
. VSD = Application/x-vsd
. vss = Application/vnd.visio
. VST = Application/vnd.visio
. VST = Application/x-vst
. VSW = Application/vnd.visio
. VSX = Application/vnd.visio
. vtx = Application/vnd.visio
. Vxml = Text/xml
. wav = Audio/wav
. wax = Audio/x-ms-wax
. wb1 = application/x-wb1
. wb2 = Application/x-wb2
. wb3 = Application/x-wb3
. wbmp = Image/vnd.wap.wbmp
. Wiz = Application/msword
. WK3 = Application/x-wk3
. WK4 = Application/x-wk4
. WKQ = APPLICATION/X-WKQ
. wks = Application/x-wks
. WM = VIDEO/X-MS-WM
. wma = Audio/x-ms-wma
. WMD = APPLICATION/X-MS-WMD
. wmf = Application/x-wmf
. WML = TEXT/VND.WAP.WML
. wmv = video/x-ms-wmv
. WMX = video/x-ms-wmx
. wmz = Application/x-ms-wmz
. WP6 = APPLICATION/X-WP6
. WPD = APPLICATION/X-WPD
. WPG = APPLICATION/X-WPG
. WPL = APPLICATION/VND.MS-WPL
. wq1 = application/x-wq1
. WR1 = Application/x-wr1
. WRI = Application/x-wri
. wrk = Application/x-wrk
. WS = Application/x-ws
. ws2 = Application/x-ws
. WSC = Text/scriptlet
. wsdl = Text/xml
. wvx = video/x-ms-wvx
. XDP = APPLICATION/VND.ADOBE.XDP
. XDR = Text/xml
. xfd = Application/vnd.adobe.xfd
. XFDF = APPLICATION/VND.ADOBE.XFDF
. xhtml = text/html
. xls = Application/vnd.ms-excel
. xls = Application/x-xls
. xlw = APPLICATION/X-XLW
. xml = Text/xml
. XPL = Audio/scpls
. XQ = Text/xml
. XQL = Text/xml
. XQuery = Text/xml
. xsd = text/xml
. xsl = text/xml
. xslt = Text/xml
. xwd = application/x-xwd
. X_b = Application/x-x_b
. x_t = application/x-x_t