各种文件对应的ContentType,拿来即用

发布时间 2023-10-27 09:45:00作者: 古兆洋

转自:https://blog.csdn.net/qq_36551991/article/details/109499487

目录
Content-Type
常见的Content-Type
更多Content-Type
Content-Type
Content-Type即内容类型,Content-Type用于定义网络文件的类型和网页的编码,决定文件接收方将以什么形式、什么编码读取这个文件,这就是经常看到一些网页点击的结果却是下载到的一个文件或一张图片的原因。

ContentType属性指定响应的 HTTP内容类型。如果未指定 ContentType,默认为TEXT/HTML。

我们在代码也经常需要定义ContentType,用于指定响应的类型

例:

1 response.setCharacterEncoding("utf-8");
2 response.setContentType("text/html;charset=utf-8");

常见的Content-Type

 1 text/html  :HTML格式
 2 text/plain :纯文本格式      
 3 text/xml   :XML格式
 4 
 5 image/gif  :gif图片格式    
 6 image/jpeg :jpg图片格式 
 7 image/png  :png图片格式
 8 
 9 application/xml     : XML数据格式
10 application/json    : JSON数据格式
11 application/pdf     : pdf格式  
12 application/msword  : Word文档格式
13 application/octet-stream : 二进制流数据(如文件下载)
14 
15 application/x-www-form-urlencoded : 
16 
17 <form encType="">中默认的encType,
18 form表单数据被编码为key/value格式发送到服务器(表单默认的提交数据的格式)。
19 服务器收到的raw body会是,name=aaa&key=bbb。
20 
21 multipart/form-data : 表单上传文件

更多Content-Type

以下是一些不那么常见的Content-Type的,但也有可能会用到,最典型的是导出excel时,我们需要将Content-Type设置为application/vnd.ms-excel,大家用到的时候可以对照

  1 .doc
  2 
  3 application/msword
  4 
  5 .dot
  6 
  7 application/msword
  8 
  9 .docx
 10 
 11 application/vnd.openxmlformats-officedocument.wordprocessingml.document
 12 
 13 .dotx
 14 
 15 application/vnd.openxmlformats-officedocument.wordprocessingml.template
 16 
 17 .docm
 18 
 19 application/vnd.ms-word.document.macroEnabled.12
 20 
 21 .dotm
 22 
 23 application/vnd.ms-word.template.macroEnabled.12
 24 
 25 .xls
 26 
 27 application/vnd.ms-excel
 28 
 29 .xlt
 30 
 31 application/vnd.ms-excel
 32 
 33 .xla
 34 
 35 application/vnd.ms-excel
 36 
 37 .xlsx
 38 
 39 application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
 40 
 41 .xltx
 42 
 43 application/vnd.openxmlformats-officedocument.spreadsheetml.template
 44 
 45 .xlsm
 46 
 47 application/vnd.ms-excel.sheet.macroEnabled.12
 48 
 49 .xltm
 50 
 51 application/vnd.ms-excel.template.macroEnabled.12
 52 
 53 .xlam
 54 
 55 application/vnd.ms-excel.addin.macroEnabled.12
 56 
 57 .xlsb
 58 
 59 application/vnd.ms-excel.sheet.binary.macroEnabled.12
 60 
 61 .ppt
 62 
 63 application/vnd.ms-powerpoint
 64 
 65 .pot
 66 
 67 application/vnd.ms-powerpoint
 68 
 69 .pps
 70 
 71 application/vnd.ms-powerpoint
 72 
 73 .ppa
 74 
 75 application/vnd.ms-powerpoint
 76 
 77 .pptx
 78 
 79 application/vnd.openxmlformats-officedocument.presentationml.presentation
 80 
 81 .potx
 82 
 83 application/vnd.openxmlformats-officedocument.presentationml.template
 84 
 85 .ppsx
 86 
 87 application/vnd.openxmlformats-officedocument.presentationml.slideshow
 88 
 89 .ppam
 90 
 91 application/vnd.ms-powerpoint.addin.macroEnabled.12
 92 
 93 .pptm
 94 
 95 application/vnd.ms-powerpoint.presentation.macroEnabled.12
 96 
 97 .potm
 98 
 99 application/vnd.ms-powerpoint.template.macroEnabled.12
100 
101 .ppsm
102 
103 application/vnd.ms-powerpoint.slideshow.macroEnabled.12

 


————————————————
版权声明:本文为CSDN博主「way_more」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_36551991/article/details/109499487