`
xiangxingchina
  • 浏览: 520230 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Struts2 文件上传 之 文件类型 allowedTypes

阅读更多
Html代码
  1. '.a'      : 'application/octet-stream',     
  2. '.ai'     : 'application/postscript',     
  3. '.aif'    : 'audio/x-aiff',     
  4. '.aifc'   : 'audio/x-aiff',     
  5. '.aiff'   : 'audio/x-aiff',     
  6. '.au'     : 'audio/basic',     
  7. '.avi'    : 'video/x-msvideo',     
  8. '.bat'    : 'text/plain',     
  9. '.bcpio' : 'application/x-bcpio',     
  10. '.bin'    : 'application/octet-stream',     
  11. '.bmp'    : 'image/x-ms-bmp',     
  12. '.c'      : 'text/plain',     
  13. # Duplicates :(     
  14. '.cdf'    : 'application/x-cdf',     
  15. '.cdf'    : 'application/x-netcdf',     
  16. '.cpio'   : 'application/x-cpio',     
  17. '.csh'    : 'application/x-csh',     
  18. '.css'    : 'text/css',     
  19. '.dll'    : 'application/octet-stream',     
  20. '.doc'    : 'application/msword',     
  21. '.dot'    : 'application/msword',     
  22. '.dvi'    : 'application/x-dvi',     
  23. '.eml'    : 'message/rfc822',     
  24. '.eps'    : 'application/postscript',     
  25. '.etx'    : 'text/x-setext',     
  26. '.exe'    : 'application/octet-stream',     
  27. '.gif'    : 'image/gif',     
  28. '.gtar'   : 'application/x-gtar',     
  29. '.h'      : 'text/plain',     
  30. '.hdf'    : 'application/x-hdf',     
  31. '.htm'    : 'text/html',     
  32. '.html'   : 'text/html',     
  33. '.ief'    : 'image/ief',     
  34. '.jpe'    : 'image/jpeg',     
  35. '.jpeg'   : 'image/jpeg',     
  36. '.jpg'    : 'image/jpeg',     
  37. '.js'     : 'application/x-javascript',     
  38. '.ksh'    : 'text/plain',     
  39. '.latex' : 'application/x-latex',     
  40. '.m1v'    : 'video/mpeg',     
  41. '.man'    : 'application/x-troff-man',     
  42. '.me'     : 'application/x-troff-me',     
  43. '.mht'    : 'message/rfc822',     
  44. '.mhtml' : 'message/rfc822',     
  45. '.mif'    : 'application/x-mif',     
  46. '.mov'    : 'video/quicktime',     
  47. '.movie' : 'video/x-sgi-movie',     
  48. '.mp2'    : 'audio/mpeg',     
  49. '.mp3'    : 'audio/mpeg',     
  50. '.mpa'    : 'video/mpeg',     
  51. '.mpe'    : 'video/mpeg',     
  52. '.mpeg'   : 'video/mpeg',     
  53. '.mpg'    : 'video/mpeg',     
  54. '.ms'     : 'application/x-troff-ms',     
  55. '.nc'     : 'application/x-netcdf',     
  56. '.nws'    : 'message/rfc822',     
  57. '.o'      : 'application/octet-stream',     
  58. '.obj'    : 'application/octet-stream',     
  59. '.oda'    : 'application/oda',     
  60. '.p12'    : 'application/x-pkcs12',     
  61. '.p7c'    : 'application/pkcs7-mime',     
  62. '.pbm'    : 'image/x-portable-bitmap',     
  63. '.pdf'    : 'application/pdf',     
  64. '.pfx'    : 'application/x-pkcs12',     
  65. '.pgm'    : 'image/x-portable-graymap',     
  66. '.pl'     : 'text/plain',     
  67. '.png'    : 'image/png',     
  68. '.pnm'    : 'image/x-portable-anymap',     
  69. '.pot'    : 'application/vnd.ms-powerpoint',     
  70. '.ppa'    : 'application/vnd.ms-powerpoint',     
  71. '.ppm'    : 'image/x-portable-pixmap',     
  72. '.pps'    : 'application/vnd.ms-powerpoint',     
  73. '.ppt'    : 'application/vnd.ms-powerpoint',     
  74. '.ps'     : 'application/postscript',     
  75. '.pwz'    : 'application/vnd.ms-powerpoint',     
  76. '.py'     : 'text/x-python',     
  77. '.pyc'    : 'application/x-python-code',     
  78. '.pyo'    : 'application/x-python-code',     
  79. '.qt'     : 'video/quicktime',     
  80. '.ra'     : 'audio/x-pn-realaudio',     
  81. '.ram'    : 'application/x-pn-realaudio',     
  82. '.ras'    : 'image/x-cmu-raster',     
  83. '.rdf'    : 'application/xml',     
  84. '.rgb'    : 'image/x-rgb',     
  85. '.roff'   : 'application/x-troff',     
  86. '.rtx'    : 'text/richtext',     
  87. '.sgm'    : 'text/x-sgml',     
  88. '.sgml'   : 'text/x-sgml',     
  89. '.sh'     : 'application/x-sh',     
  90. '.shar'   : 'application/x-shar',     
  91. '.snd'    : 'audio/basic',     
  92. '.so'     : 'application/octet-stream',     
  93. '.src'    : 'application/x-wais-source',     
  94. '.sv4cpio': 'application/x-sv4cpio',     
  95. '.sv4crc' : 'application/x-sv4crc',     
  96. '.swf'    : 'application/x-shockwave-flash',     
  97. '.t'      : 'application/x-troff',     
  98. '.tar'    : 'application/x-tar',     
  99. '.tcl'    : 'application/x-tcl',     
  100.     
  101. '.tex'    : 'application/x-tex',     
  102. '.texi'   : 'application/x-texinfo',     
  103. '.texinfo': 'application/x-texinfo',     
  104. '.tif'    : 'image/tiff',     
  105. '.tiff'   : 'image/tiff',     
  106. '.tr'     : 'application/x-troff',     
  107. '.tsv'    : 'text/tab-separated-values',     
  108. '.txt'    : 'text/plain',     
  109. '.ustar' : 'application/x-ustar',     
  110. '.vcf'    : 'text/x-vcard',     
  111. '.wav'    : 'audio/x-wav',     
  112. '.wiz'    : 'application/msword',     
  113. '.wsdl'   : 'application/xml',     
  114. '.xbm'    : 'image/x-xbitmap',     
  115. '.xlb'    : 'application/vnd.ms-excel',     
  116. # Duplicates :(     
  117. '.xls'    : 'application/excel',     
  118. '.xls'    : 'application/vnd.ms-excel',     
  119. '.xml'    : 'text/xml',     
  120. '.xpdl'   : 'application/xml',     
  121. '.xpm'    : 'image/x-xpixmap',     
  122. '.xsl'    : 'application/xml',     
  123. '.xwd'    : 'image/x-xwindowdump',     
  124. '.zip'    : 'application/zip',  
  125.   
  126.   
  127. firefox 和 ie 的文件类型区别   
  128. Java代码   
  129. firefox image/jpeg image/bmp image/gif image/png      
  130.     
  131. ie 6 image/pjpeg image/bmp image/gif image/x-png      
  132.     
  133. ie 7 image/pjpeg image/bmp image/gif image/x-png      
  134.     
  135. ie 8 image/pjpeg image/bmp image/gif image/x-png    
'.a'      : 'application/octet-stream',   
'.ai'     : 'application/postscript',   
'.aif'    : 'audio/x-aiff',   
'.aifc'   : 'audio/x-aiff',   
'.aiff'   : 'audio/x-aiff',   
'.au'     : 'audio/basic',   
'.avi'    : 'video/x-msvideo',   
'.bat'    : 'text/plain',   
'.bcpio' : 'application/x-bcpio',   
'.bin'    : 'application/octet-stream',   
'.bmp'    : 'image/x-ms-bmp',   
'.c'      : 'text/plain',   
# Duplicates :(   
'.cdf'    : 'application/x-cdf',   
'.cdf'    : 'application/x-netcdf',   
'.cpio'   : 'application/x-cpio',   
'.csh'    : 'application/x-csh',   
'.css'    : 'text/css',   
'.dll'    : 'application/octet-stream',   
'.doc'    : 'application/msword',   
'.dot'    : 'application/msword',   
'.dvi'    : 'application/x-dvi',   
'.eml'    : 'message/rfc822',   
'.eps'    : 'application/postscript',   
'.etx'    : 'text/x-setext',   
'.exe'    : 'application/octet-stream',   
'.gif'    : 'image/gif',   
'.gtar'   : 'application/x-gtar',   
'.h'      : 'text/plain',   
'.hdf'    : 'application/x-hdf',   
'.htm'    : 'text/html',   
'.html'   : 'text/html',   
'.ief'    : 'image/ief',   
'.jpe'    : 'image/jpeg',   
'.jpeg'   : 'image/jpeg',   
'.jpg'    : 'image/jpeg',   
'.js'     : 'application/x-javascript',   
'.ksh'    : 'text/plain',   
'.latex' : 'application/x-latex',   
'.m1v'    : 'video/mpeg',   
'.man'    : 'application/x-troff-man',   
'.me'     : 'application/x-troff-me',   
'.mht'    : 'message/rfc822',   
'.mhtml' : 'message/rfc822',   
'.mif'    : 'application/x-mif',   
'.mov'    : 'video/quicktime',   
'.movie' : 'video/x-sgi-movie',   
'.mp2'    : 'audio/mpeg',   
'.mp3'    : 'audio/mpeg',   
'.mpa'    : 'video/mpeg',   
'.mpe'    : 'video/mpeg',   
'.mpeg'   : 'video/mpeg',   
'.mpg'    : 'video/mpeg',   
'.ms'     : 'application/x-troff-ms',   
'.nc'     : 'application/x-netcdf',   
'.nws'    : 'message/rfc822',   
'.o'      : 'application/octet-stream',   
'.obj'    : 'application/octet-stream',   
'.oda'    : 'application/oda',   
'.p12'    : 'application/x-pkcs12',   
'.p7c'    : 'application/pkcs7-mime',   
'.pbm'    : 'image/x-portable-bitmap',   
'.pdf'    : 'application/pdf',   
'.pfx'    : 'application/x-pkcs12',   
'.pgm'    : 'image/x-portable-graymap',   
'.pl'     : 'text/plain',   
'.png'    : 'image/png',   
'.pnm'    : 'image/x-portable-anymap',   
'.pot'    : 'application/vnd.ms-powerpoint',   
'.ppa'    : 'application/vnd.ms-powerpoint',   
'.ppm'    : 'image/x-portable-pixmap',   
'.pps'    : 'application/vnd.ms-powerpoint',   
'.ppt'    : 'application/vnd.ms-powerpoint',   
'.ps'     : 'application/postscript',   
'.pwz'    : 'application/vnd.ms-powerpoint',   
'.py'     : 'text/x-python',   
'.pyc'    : 'application/x-python-code',   
'.pyo'    : 'application/x-python-code',   
'.qt'     : 'video/quicktime',   
'.ra'     : 'audio/x-pn-realaudio',   
'.ram'    : 'application/x-pn-realaudio',   
'.ras'    : 'image/x-cmu-raster',   
'.rdf'    : 'application/xml',   
'.rgb'    : 'image/x-rgb',   
'.roff'   : 'application/x-troff',   
'.rtx'    : 'text/richtext',   
'.sgm'    : 'text/x-sgml',   
'.sgml'   : 'text/x-sgml',   
'.sh'     : 'application/x-sh',   
'.shar'   : 'application/x-shar',   
'.snd'    : 'audio/basic',   
'.so'     : 'application/octet-stream',   
'.src'    : 'application/x-wais-source',   
'.sv4cpio': 'application/x-sv4cpio',   
'.sv4crc' : 'application/x-sv4crc',   
'.swf'    : 'application/x-shockwave-flash',   
'.t'      : 'application/x-troff',   
'.tar'    : 'application/x-tar',   
'.tcl'    : 'application/x-tcl',   
  
'.tex'    : 'application/x-tex',   
'.texi'   : 'application/x-texinfo',   
'.texinfo': 'application/x-texinfo',   
'.tif'    : 'image/tiff',   
'.tiff'   : 'image/tiff',   
'.tr'     : 'application/x-troff',   
'.tsv'    : 'text/tab-separated-values',   
'.txt'    : 'text/plain',   
'.ustar' : 'application/x-ustar',   
'.vcf'    : 'text/x-vcard',   
'.wav'    : 'audio/x-wav',   
'.wiz'    : 'application/msword',   
'.wsdl'   : 'application/xml',   
'.xbm'    : 'image/x-xbitmap',   
'.xlb'    : 'application/vnd.ms-excel',   
# Duplicates :(   
'.xls'    : 'application/excel',   
'.xls'    : 'application/vnd.ms-excel',   
'.xml'    : 'text/xml',   
'.xpdl'   : 'application/xml',   
'.xpm'    : 'image/x-xpixmap',   
'.xsl'    : 'application/xml',   
'.xwd'    : 'image/x-xwindowdump',   
'.zip'    : 'application/zip',


firefox 和 ie 的文件类型区别 
Java代码 
firefox image/jpeg image/bmp image/gif image/png    
  
ie 6 image/pjpeg image/bmp image/gif image/x-png    
  
ie 7 image/pjpeg image/bmp image/gif image/x-png    
  
ie 8 image/pjpeg image/bmp image/gif image/x-png  

 

Html代码
  1. --------------------------------------------  
  2. IE下载Office2007文件时在下载对话框中变成ZIP文件问题的解决   
  3.   
  4.   
  5.  从 IIS或者Tomcat之类的Web服务器通过二进制流下载文件时(比如通过设置Header为Content- disposition:inline),如果被下载的文件是Office2007的dotx,docx,pot等后缀的时候,下载对话框中的图标会变成 ZIP的,相应的文件名也会成为zip为扩展后缀的文件。其实出现这样的情况,是由于IE中对下载文件类型的判断,假如找不到相应后缀的MIME的话,会 自动根据数据流来判断文件的类型,而微软对Office2007的格式做了和以前完全不同的处理。  
  6.   
  7.   
  8.   
  9. 以 前的Office文档是100%的二进制格式。第三方的工具操作起来非常不方便,而 Office2007从整体上都是基于XML格式的,这里并不是说 Office2007文档可以保存成XML格式。而是Office2007默认的文档格式就是XML的(Word的docx、Excel的xlsx等)。 也许有人会感到奇怪,用文本编辑器打开docx后,显示的仍然是二进制格式,并不是什么 XML。其实docx并不是普通的XML格式,当然,也不只是一 个XML文件,docx本质上是一个zip文件,里面有一系列的xml、目录和其他的文件。如果我们将docx改成zip。就可以用winzip等软件将 其解开。  
  10.   
  11. 正是由于这样的原因,当MIME中不存在相对应的Office2007类型的情况下,被自动识别为ZIP文件了。解决的方法很简单,在Server端添加MIME映射就可以了。Tomcat的话,可以在Web.xml中找到< mime-mapping > </ mime-mapping > 这样的定义,按照规则添加就可以了,IIS中按照下面的方法添加(以XML为例):  
  12.   
  13. 1.选择Default Web Site,弹出Properties对话框。   
  14. 2.选择HTTP Headers标签。   
  15. 3.在MIME Map下,单击File Types 标签并选择New Type。   
  16. 4.在Extension 域中键入.xml,在 Content Type 域中键入text/xml, 然后单击OK。  
  17. 至于什么是MIME,一般的人应该都知道,这里简单的解释一下:  
  18. MIME (Multipurpose Internet Mail Extensions, 多目的Internet邮件扩展)是创建用于电子邮件交换,网络文档,及企业网和Internet上的其他应用程序中的文件格式的规范。每个MIME格式 包含一个MIME内容类型(”MIME type”)和指示存储在这个文件中的数据的子类型。MIME类型和子类型一般以类型/子类型的形式列出。 MIME格式的内容广泛用于网络文档中  
  19.   
  20. 下面收集了大部分文件的扩展名和相应的MIME对应,有需要的可以在列表中找到并添加。   
  21.   
  22. .asx,video/x-ms-asf  
  23. .xml,text/xml  
  24. .tsv,text/tab-separated-values  
  25. .ra,audio/x-pn-realaudio  
  26. .sv4crc,application/x-sv4crc  
  27. .spc,application/x-pkcs7-certificates  
  28. .pmc,application/x-perfmon  
  29. .lit,application/x-ms-reader  
  30. .crd,application/x-mscardfile  
  31. .isp,application/x-internet-signup  
  32. .wmlsc,application/vnd.wap.wmlscriptc  
  33. .vst,application/vnd.visio  
  34. .xlam,application/vnd.ms-excel.addin.macroEnabled.12  
  35. .ttf,application/octet-stream  
  36. .pfm,application/octet-stream  
  37. .csv,application/octet-stream  
  38. .aaf,application/octet-stream  
  39. .one,application/onenote  
  40. .hta,application/hta  
  41. .atom,application/atom+xml  
  42. .323,text/h323  
  43. .mhtml,message/rfc822  
  44. .midi,audio/mid  
  45. .p7r,application/x-pkcs7-certreqresp  
  46. .mny,application/x-msmoney  
  47. .clp,application/x-msclip  
  48. .vsd,application/vnd.visio  
  49. .lpk,application/octet-stream  
  50. .bin,application/octet-stream  
  51. .onetoc,application/onenote  
  52. .x,application/directx  
  53. .wvx,video/x-ms-wvx  
  54. .vcf,text/x-vcard  
  55. .htc,text/x-component  
  56. .htt,text/webviewhtml  
  57. .h,text/plain  
  58. .mht,message/rfc822  
  59. .mid,audio/mid  
  60. .p7b,application/x-pkcs7-certificates  
  61. .gz,application/x-gzip  
  62. .dvi,application/x-dvi  
  63. .cpio,application/x-cpio  
  64. .vdx,application/vnd.ms-visio.viewer  
  65. .sldm,application/vnd.ms-powerpoint.slide.macroEnabled.12  
  66. .xlm,application/vnd.ms-excel  
  67. .fdf,application/vnd.fdf  
  68. .setreg,application/set-registration-initiation  
  69. .eps,application/postscript  
  70. .p7s,application/pkcs7-signature  
  71. .toc,application/octet-stream  
  72. .mdp,application/octet-stream  
  73. .ics,application/octet-stream  
  74. .chm,application/octet-stream  
  75. .asi,application/octet-stream  
  76. .afm,application/octet-stream  
  77. .evy,application/envoy  
  78. .wmp,video/x-ms-wmp  
  79. .qt,video/quicktime  
  80. .mpv2,video/mpeg  
  81. .xslt,text/xml  
  82. .etx,text/x-setext  
  83. .cod,image/cis-cod  
  84. .snd,audio/basic  
  85. .au,audio/basic  
  86. .man,application/x-troff-man  
  87. .qtl,application/x-quicktimeplayer  
  88. .pmw,application/x-perfmon  
  89. .class,application/x-java-applet  
  90. .iii,application/x-iphone  
  91. .csh,application/x-csh  
  92. .z,application/x-compress  
  93. .vtx,application/vnd.visio  
  94. .vsw,application/vnd.visio  
  95. .wps,application/vnd.ms-works  
  96. .potx,application/vnd.openxmlformats-officedocument.presentationml.template  
  97. .ps,application/postscript  
  98. .p7c,application/pkcs7-mime  
  99. .thn,application/octet-stream  
  100. .mso,application/octet-stream  
  101. .dot,application/msword  
  102. .doc,application/msword  
  103. .sgml,text/sgml  
  104. .nws,message/rfc822  
  105. .pbm,image/x-portable-bitmap  
  106. .ief,image/ief  
  107. .wav,audio/wav  
  108. .texi,application/x-texinfo  
  109. .mvb,application/x-msmediaview  
  110. .hdf,application/x-hdf  
  111. .vsx,application/vnd.visio  
  112. .dotm,application/vnd.ms-word.template.macroEnabled.12  
  113. .docm,application/vnd.ms-word.document.macroEnabled.12  
  114. .pptx,application/vnd.openxmlformats-officedocument.presentationml.presentation  
  115. .psm,application/octet-stream  
  116. .java,application/octet-stream  
  117. .eot,application/octet-stream  
  118. .jar,application/java-archive  
  119. .mpeg,video/mpeg  
  120. .xsf,text/xml  
  121. .map,text/plain  
  122. .uls,text/iuls  
  123. .rf,image/vnd.rn-realflash  
  124. .m3u,audio/x-mpegurl  
  125. .wma,audio/x-ms-wma  
  126. .aifc,audio/aiff  
  127. .mdb,application/x-msaccess  
  128. .mvc,application/x-miva-compiled  
  129. .stl,application/vnd.ms-pki.stl  
  130. .ppsx,application/vnd.openxmlformats-officedocument.presentationml.slideshow  
  131. .xlsb,application/vnd.ms-excel.sheet.binary.macroEnabled.12  
  132. .setpay,application/set-payment-initiation  
  133. .prm,application/octet-stream  
  134. .mix,application/octet-stream  
  135. .lzh,application/octet-stream  
  136. .hhk,application/octet-stream  
  137. .onepkg,application/onenote  
  138. .xaf,x-world/x-vrml  
  139. .flr,x-world/x-vrml  
  140. .IVF,video/x-ivf  
  141. .cnf,text/plain  
  142. .asm,text/plain  
  143. .tiff,image/tiff  
  144. .wax,audio/x-ms-wax  
  145. .ms,application/x-troff-ms  
  146. .tcl,application/x-tcl  
  147. .shar,application/x-shar  
  148. .sh,application/x-sh  
  149. .nc,application/x-netcdf  
  150. .hlp,application/winhlp  
  151. .oda,application/oda  
  152. .pfb,application/octet-stream  
  153. .fla,application/octet-stream  
  154. .wm,video/x-ms-wm  
  155. .rgb,image/x-rgb  
  156. .ppm,image/x-portable-pixmap  
  157. .ram,audio/x-pn-realaudio  
  158. .sit,application/x-stuffit  
  159. .dir,application/x-director  
  160. .mpp,application/vnd.ms-project  
  161. .xla,application/vnd.ms-excel  
  162. .ssm,application/streamingmedia  
  163. .axs,application/olescript  
  164. .ods,application/oleobject  
  165. .psp,application/octet-stream  
  166. .jpb,application/octet-stream  
  167. .wrz,x-world/x-vrml  
  168. .m1v,video/mpeg  
  169. .mno,text/xml  
  170. .cmx,image/x-cmx  
  171. .jpeg,image/jpeg  
  172. .dib,image/bmp  
  173. .rmi,audio/mid  
  174. .aiff,audio/aiff  
  175. .wmd,application/x-ms-wmd  
  176. .wri,application/x-mswrite  
  177. .pub,application/x-mspublisher  
  178. .ins,application/x-internet-signup  
  179. .wks,application/vnd.ms-works  
  180. .xls,application/vnd.ms-excel  
  181. .ai,application/postscript  
  182. .crl,application/pkix-crl  
  183. .qxd,application/octet-stream  
  184. .dwp,application/octet-stream  
  185. .xof,x-world/x-vrml  
  186. .wmv,video/x-ms-wmv  
  187. .nsc,video/x-ms-asf  
  188. .mpa,video/mpeg  
  189. .pnm,image/x-portable-anymap  
  190. .rpm,audio/x-pn-realaudio-plugin  
  191. .aif,audio/x-aiff  
  192. .me,application/x-troff-me  
  193. .pml,application/x-perfmon  
  194. .trm,application/x-msterminal  
  195. .m13,application/x-msmediaview  
  196. .js,application/x-javascript  
  197. .dxr,application/x-director  
  198. .potm,application/vnd.ms-powerpoint.template.macroEnabled.12  
  199. .xltx,application/vnd.openxmlformats-officedocument.spreadsheetml.template  
  200. .xlt,application/vnd.ms-excel  
  201. .xlc,application/vnd.ms-excel  
  202. .p10,application/pkcs10  
  203. .smi,application/octet-stream  
  204. .sea,application/octet-stream  
  205. .hqx,application/mac-binhex40  
  206. .spl,application/futuresplash  
  207. .movie,video/x-sgi-movie  
  208. .lsf,video/x-la-asf  
  209. .txt,text/plain  
  210. .jfif,image/pjpeg  
  211. .jpe,image/jpeg  
  212. .zip,application/x-zip-compressed  
  213. .wmf,application/x-msmetafile  
  214. .m14,application/x-msmediaview  
  215. .latex,application/x-latex  
  216. .wcm,application/vnd.ms-works  
  217. .pptm,application/vnd.ms-powerpoint.presentation.macroEnabled.12  
  218. .xlsx,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet  
  219. .hhp,application/octet-stream  
  220. .aca,application/octet-stream  
  221. .accdb,application/msaccess  
  222. .jcz,application/liquidmotion  
  223. .wrl,x-world/x-vrml  
  224. .wmx,video/x-ms-wmx  
  225. .asr,video/x-ms-asf  
  226. .lsx,video/x-la-asf  
  227. .xsl,text/xml  
  228. .html,text/html  
  229. .tif,image/tiff  
  230. .der,application/x-x509-ca-cert  
  231. .pfx,application/x-pkcs12  
  232. .p12,application/x-pkcs12  
  233. .ppsm,application/vnd.ms-powerpoint.slideshow.macroEnabled.12  
  234. .cur,application/octet-stream  
  235. .accdt,application/msaccess  
  236. .hdml,text/x-hdml  
  237. .htm,text/html  
  238. .xbm,image/x-xbitmap  
  239. .jpg,image/jpeg  
  240. .texinfo,application/x-texinfo  
  241. .ppam,application/vnd.ms-powerpoint.addin.macroEnabled.12  
  242. .xlw,application/vnd.ms-excel  
  243. .rm,application/vnd.rn-realmedia  
  244. .pdf,application/pdf  
  245. .rar,application/octet-stream  
  246. .psd,application/octet-stream  
  247. .inf,application/octet-stream  
  248. .emz,application/octet-stream  
  249. .dsp,application/octet-stream  
  250. .onea,application/onenote  
  251. .jck,application/liquidmotion  
  252. .mpe,video/mpeg  
  253. .mp2,video/mpeg  
  254. .sct,text/scriptlet  
  255. .ras,image/x-cmu-raster  
  256. .swf,application/x-shockwave-flash  
  257. .wmz,application/x-ms-wmz  
  258. .gtar,application/x-gtar  
  259. .dcr,application/x-director  
  260. .sldx,application/vnd.openxmlformats-officedocument.presentationml.slide  
  261. .pps,application/vnd.ms-pps  
  262. .p7m,application/pkcs7-mime  
  263. .xsn,application/octet-stream  
  264. .ocx,application/octet-stream  
  265. .accde,application/msaccess  
  266. .mov,video/quicktime  
  267. .wmls,text/vnd.wap.wmlscript  
  268. .cpp,text/plain  
  269. .c,text/plain  
  270. .bas,text/plain  
  271. .css,text/css  
  272. .art,image/x-jg  
  273. .mp3,audio/mpeg  
  274. .t,application/x-troff  
  275. .roff,application/x-troff  
  276. .tar,application/x-tar  
  277. .hhc,application/x-oleobject  
  278. .scd,application/x-msschedule  
  279. .pko,application/vnd.ms-pki.pko  
  280. .sst,application/vnd.ms-pki.certstore  
  281. .ppt,application/vnd.ms-powerpoint  
  282. .xtp,application/octet-stream  
  283. .u32,application/octet-stream  
  284. .pcx,application/octet-stream  
  285. .msi,application/octet-stream  
  286. .exe,application/octet-stream  
  287. .asd,application/octet-stream  
  288. .onetoc2,application/onenote  
  289. .fif,application/fractals  
  290. .mpg,video/mpeg  
  291. .vml,text/xml  
  292. .xdr,text/plain  
  293. .vcs,text/plain  
  294. .hxt,text/html  
  295. .eml,message/rfc822  
  296. .xpm,image/x-xpixmap  
  297. .ico,image/x-icon  
  298. .gif,image/gif  
  299. .dwf,drawing/x-dwf  
  300. .src,application/x-wais-source  
  301. .tr,application/x-troff  
  302. .pmr,application/x-perfmon  
  303. .pma,application/x-perfmon  
  304. .dll,application/x-msdownload  
  305. .bcpio,application/x-bcpio  
  306. .wmlc,application/vnd.wap.wmlc  
  307. .wdb,application/vnd.ms-works  
  308. .dotx,application/vnd.openxmlformats-officedocument.wordprocessingml.template  
  309. .docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document  
  310. .pot,application/vnd.ms-powerpoint  
  311. .xltm,application/vnd.ms-excel.template.macroEnabled.12  
  312. .rtf,application/rtf  
  313. .prf,application/pics-rules  
  314. .snp,application/octet-stream  
  315. .cab,application/octet-stream  
  316. .avi,video/x-msvideo  
  317. .asf,video/x-ms-asf  
  318. .dtd,text/xml  
  319. .wml,text/vnd.wap.wml  
  320. .vbs,text/vbscript  
  321. .rtx,text/richtext  
  322. .dlm,text/dlm  
  323. .xwd,image/x-xwindowdump  
  324. .pgm,image/x-portable-graymap  
  325. .bmp,image/bmp  
  326. .crt,application/x-x509-ca-cert  
  327. .ustar,application/x-ustar  
  328. .tex,application/x-tex  
  329. .sv4cpio,application/x-sv4cpio  
  330. .tgz,application/x-compressed  
  331. .cdf,application/x-cdf  
  332. .vss,application/vnd.visio  
  333. .cat,application/vnd.ms-pki.seccat  
  334. .thmx,application/vnd.ms-officetheme  
  335. .xlsm,application/vnd.ms-excel.sheet.macroEnabled.12  
  336. .prx,application/octet-stream  
  337. .pcz,application/octet-stream  
  338. .onetmp,application/onenote  
  339. .acx,application/internet-property-stream  
  340. .wsdl,text/xml  
  341. .disco,text/xml  
  342. .xsd,text/xml  
  343. .wbmp,image/vnd.wap.wbmp  
  344. .png,image/png  
  345. .pnz,image/png  
  346. .smd,audio/x-smd  
  347. .smz,audio/x-smd  
  348. .smx,audio/x-smd  
--------------------------------------------
IE下载Office2007文件时在下载对话框中变成ZIP文件问题的解决 


 从IIS或者Tomcat之类的Web服务器通过二进制流下载文件时(比如通过设置Header为Content-disposition:inline),如果被下载的文件是Office2007的dotx,docx,pot等后缀的时候,下载对话框中的图标会变成ZIP的,相应的文件名也会成为zip为扩展后缀的文件。其实出现这样的情况,是由于IE中对下载文件类型的判断,假如找不到相应后缀的MIME的话,会自动根据数据流来判断文件的类型,而微软对Office2007的格式做了和以前完全不同的处理。



以前的Office文档是100%的二进制格式。第三方的工具操作起来非常不方便,而 Office2007从整体上都是基于XML格式的,这里并不是说Office2007文档可以保存成XML格式。而是Office2007默认的文档格式就是XML的(Word的docx、Excel的xlsx等)。也许有人会感到奇怪,用文本编辑器打开docx后,显示的仍然是二进制格式,并不是什么 XML。其实docx并不是普通的XML格式,当然,也不只是一个XML文件,docx本质上是一个zip文件,里面有一系列的xml、目录和其他的文件。如果我们将docx改成zip。就可以用winzip等软件将其解开。

正是由于这样的原因,当MIME中不存在相对应的Office2007类型的情况下,被自动识别为ZIP文件了。解决的方法很简单,在Server端添加MIME映射就可以了。Tomcat的话,可以在Web.xml中找到<mime-mapping></mime-mapping>这样的定义,按照规则添加就可以了,IIS中按照下面的方法添加(以XML为例):

1.选择Default Web Site,弹出Properties对话框。 
2.选择HTTP Headers标签。 
3.在MIME Map下,单击File Types 标签并选择New Type。 
4.在Extension 域中键入.xml,在 Content Type 域中键入text/xml, 然后单击OK。
至于什么是MIME,一般的人应该都知道,这里简单的解释一下:
MIME (Multipurpose Internet Mail Extensions,多目的Internet邮件扩展)是创建用于电子邮件交换,网络文档,及企业网和Internet上的其他应用程序中的文件格式的规范。每个MIME格式包含一个MIME内容类型(”MIME type”)和指示存储在这个文件中的数据的子类型。MIME类型和子类型一般以类型/子类型的形式列出。MIME格式的内容广泛用于网络文档中

下面收集了大部分文件的扩展名和相应的MIME对应,有需要的可以在列表中找到并添加。 

.asx,video/x-ms-asf
.xml,text/xml
.tsv,text/tab-separated-values
.ra,audio/x-pn-realaudio
.sv4crc,application/x-sv4crc
.spc,application/x-pkcs7-certificates
.pmc,application/x-perfmon
.lit,application/x-ms-reader
.crd,application/x-mscardfile
.isp,application/x-internet-signup
.wmlsc,application/vnd.wap.wmlscriptc
.vst,application/vnd.visio
.xlam,application/vnd.ms-excel.addin.macroEnabled.12
.ttf,application/octet-stream
.pfm,application/octet-stream
.csv,application/octet-stream
.aaf,application/octet-stream
.one,application/onenote
.hta,application/hta
.atom,application/atom+xml
.323,text/h323
.mhtml,message/rfc822
.midi,audio/mid
.p7r,application/x-pkcs7-certreqresp
.mny,application/x-msmoney
.clp,application/x-msclip
.vsd,application/vnd.visio
.lpk,application/octet-stream
.bin,application/octet-stream
.onetoc,application/onenote
.x,application/directx
.wvx,video/x-ms-wvx
.vcf,text/x-vcard
.htc,text/x-component
.htt,text/webviewhtml
.h,text/plain
.mht,message/rfc822
.mid,audio/mid
.p7b,application/x-pkcs7-certificates
.gz,application/x-gzip
.dvi,application/x-dvi
.cpio,application/x-cpio
.vdx,application/vnd.ms-visio.viewer
.sldm,application/vnd.ms-powerpoint.slide.macroEnabled.12
.xlm,application/vnd.ms-excel
.fdf,application/vnd.fdf
.setreg,application/set-registration-initiation
.eps,application/postscript
.p7s,application/pkcs7-signature
.toc,application/octet-stream
.mdp,application/octet-stream
.ics,application/octet-stream
.chm,application/octet-stream
.asi,application/octet-stream
.afm,application/octet-stream
.evy,application/envoy
.wmp,video/x-ms-wmp
.qt,video/quicktime
.mpv2,video/mpeg
.xslt,text/xml
.etx,text/x-setext
.cod,image/cis-cod
.snd,audio/basic
.au,audio/basic
.man,application/x-troff-man
.qtl,application/x-quicktimeplayer
.pmw,application/x-perfmon
.class,application/x-java-applet
.iii,application/x-iphone
.csh,application/x-csh
.z,application/x-compress
.vtx,application/vnd.visio
.vsw,application/vnd.visio
.wps,application/vnd.ms-works
.potx,application/vnd.openxmlformats-officedocument.presentationml.template
.ps,application/postscript
.p7c,application/pkcs7-mime
.thn,application/octet-stream
.mso,application/octet-stream
.dot,application/msword
.doc,application/msword
.sgml,text/sgml
.nws,message/rfc822
.pbm,image/x-portable-bitmap
.ief,image/ief
.wav,audio/wav
.texi,application/x-texinfo
.mvb,application/x-msmediaview
.hdf,application/x-hdf
.vsx,application/vnd.visio
.dotm,application/vnd.ms-word.template.macroEnabled.12
.docm,application/vnd.ms-word.document.macroEnabled.12
.pptx,application/vnd.openxmlformats-officedocument.presentationml.presentation
.psm,application/octet-stream
.java,application/octet-stream
.eot,application/octet-stream
.jar,application/java-archive
.mpeg,video/mpeg
.xsf,text/xml
.map,text/plain
.uls,text/iuls
.rf,image/vnd.rn-realflash
.m3u,audio/x-mpegurl
.wma,audio/x-ms-wma
.aifc,audio/aiff
.mdb,application/x-msaccess
.mvc,application/x-miva-compiled
.stl,application/vnd.ms-pki.stl
.ppsx,application/vnd.openxmlformats-officedocument.presentationml.slideshow
.xlsb,application/vnd.ms-excel.sheet.binary.macroEnabled.12
.setpay,application/set-payment-initiation
.prm,application/octet-stream
.mix,application/octet-stream
.lzh,application/octet-stream
.hhk,application/octet-stream
.onepkg,application/onenote
.xaf,x-world/x-vrml
.flr,x-world/x-vrml
.IVF,video/x-ivf
.cnf,text/plain
.asm,text/plain
.tiff,image/tiff
.wax,audio/x-ms-wax
.ms,application/x-troff-ms
.tcl,application/x-tcl
.shar,application/x-shar
.sh,application/x-sh
.nc,application/x-netcdf
.hlp,application/winhlp
.oda,application/oda
.pfb,application/octet-stream
.fla,application/octet-stream
.wm,video/x-ms-wm
.rgb,image/x-rgb
.ppm,image/x-portable-pixmap
.ram,audio/x-pn-realaudio
.sit,application/x-stuffit
.dir,application/x-director
.mpp,application/vnd.ms-project
.xla,application/vnd.ms-excel
.ssm,application/streamingmedia
.axs,application/olescript
.ods,application/oleobject
.psp,application/octet-stream
.jpb,application/octet-stream
.wrz,x-world/x-vrml
.m1v,video/mpeg
.mno,text/xml
.cmx,image/x-cmx
.jpeg,image/jpeg
.dib,image/bmp
.rmi,audio/mid
.aiff,audio/aiff
.wmd,application/x-ms-wmd
.wri,application/x-mswrite
.pub,application/x-mspublisher
.ins,application/x-internet-signup
.wks,application/vnd.ms-works
.xls,application/vnd.ms-excel
.ai,application/postscript
.crl,application/pkix-crl
.qxd,application/octet-stream
.dwp,application/octet-stream
.xof,x-world/x-vrml
.wmv,video/x-ms-wmv
.nsc,video/x-ms-asf
.mpa,video/mpeg
.pnm,image/x-portable-anymap
.rpm,audio/x-pn-realaudio-plugin
.aif,audio/x-aiff
.me,application/x-troff-me
.pml,application/x-perfmon
.trm,application/x-msterminal
.m13,application/x-msmediaview
.js,application/x-javascript
.dxr,application/x-director
.potm,application/vnd.ms-powerpoint.template.macroEnabled.12
.xltx,application/vnd.openxmlformats-officedocument.spreadsheetml.template
.xlt,application/vnd.ms-excel
.xlc,application/vnd.ms-excel
.p10,application/pkcs10
.smi,application/octet-stream
.sea,application/octet-stream
.hqx,application/mac-binhex40
.spl,application/futuresplash
.movie,video/x-sgi-movie
.lsf,video/x-la-asf
.txt,text/plain
.jfif,image/pjpeg
.jpe,image/jpeg
.zip,application/x-zip-compressed
.wmf,application/x-msmetafile
.m14,application/x-msmediaview
.latex,application/x-latex
.wcm,application/vnd.ms-works
.pptm,application/vnd.ms-powerpoint.presentation.macroEnabled.12
.xlsx,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.hhp,application/octet-stream
.aca,application/octet-stream
.accdb,application/msaccess
.jcz,application/liquidmotion
.wrl,x-world/x-vrml
.wmx,video/x-ms-wmx
.asr,video/x-ms-asf
.lsx,video/x-la-asf
.xsl,text/xml
.html,text/html
.tif,image/tiff
.der,application/x-x509-ca-cert
.pfx,application/x-pkcs12
.p12,application/x-pkcs12
.ppsm,application/vnd.ms-powerpoint.slideshow.macroEnabled.12
.cur,application/octet-stream
.accdt,application/msaccess
.hdml,text/x-hdml
.htm,text/html
.xbm,image/x-xbitmap
.jpg,image/jpeg
.texinfo,application/x-texinfo
.ppam,application/vnd.ms-powerpoint.addin.macroEnabled.12
.xlw,application/vnd.ms-excel
.rm,application/vnd.rn-realmedia
.pdf,application/pdf
.rar,application/octet-stream
.psd,application/octet-stream
.inf,application/octet-stream
.emz,application/octet-stream
.dsp,application/octet-stream
.onea,application/onenote
.jck,application/liquidmotion
.mpe,video/mpeg
.mp2,video/mpeg
.sct,text/scriptlet
.ras,image/x-cmu-raster
.swf,application/x-shockwave-flash
.wmz,application/x-ms-wmz
.gtar,application/x-gtar
.dcr,application/x-director
.sldx,application/vnd.openxmlformats-officedocument.presentationml.slide
.pps,application/vnd.ms-pps
.p7m,application/pkcs7-mime
.xsn,application/octet-stream
.ocx,application/octet-stream
.accde,application/msaccess
.mov,video/quicktime
.wmls,text/vnd.wap.wmlscript
.cpp,text/plain
.c,text/plain
.bas,text/plain
.css,text/css
.art,image/x-jg
.mp3,audio/mpeg
.t,application/x-troff
.roff,application/x-troff
.tar,application/x-tar
.hhc,application/x-oleobject
.scd,application/x-msschedule
.pko,application/vnd.ms-pki.pko
.sst,application/vnd.ms-pki.certstore
.ppt,application/vnd.ms-powerpoint
.xtp,application/octet-stream
.u32,application/octet-stream
.pcx,application/octet-stream
.msi,application/octet-stream
.exe,application/octet-stream
.asd,application/octet-stream
.onetoc2,application/onenote
.fif,application/fractals
.mpg,video/mpeg
.vml,text/xml
.xdr,text/plain
.vcs,text/plain
.hxt,text/html
.eml,message/rfc822
.xpm,image/x-xpixmap
.ico,image/x-icon
.gif,image/gif
.dwf,drawing/x-dwf
.src,application/x-wais-source
.tr,application/x-troff
.pmr,application/x-perfmon
.pma,application/x-perfmon
.dll,application/x-msdownload
.bcpio,application/x-bcpio
.wmlc,application/vnd.wap.wmlc
.wdb,application/vnd.ms-works
.dotx,application/vnd.openxmlformats-officedocument.wordprocessingml.template
.docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document
.pot,application/vnd.ms-powerpoint
.xltm,application/vnd.ms-excel.template.macroEnabled.12
.rtf,application/rtf
.prf,application/pics-rules
.snp,application/octet-stream
.cab,application/octet-stream
.avi,video/x-msvideo
.asf,video/x-ms-asf
.dtd,text/xml
.wml,text/vnd.wap.wml
.vbs,text/vbscript
.rtx,text/richtext
.dlm,text/dlm
.xwd,image/x-xwindowdump
.pgm,image/x-portable-graymap
.bmp,image/bmp
.crt,application/x-x509-ca-cert
.ustar,application/x-ustar
.tex,application/x-tex
.sv4cpio,application/x-sv4cpio
.tgz,application/x-compressed
.cdf,application/x-cdf
.vss,application/vnd.visio
.cat,application/vnd.ms-pki.seccat
.thmx,application/vnd.ms-officetheme
.xlsm,application/vnd.ms-excel.sheet.macroEnabled.12
.prx,application/octet-stream
.pcz,application/octet-stream
.onetmp,application/onenote
.acx,application/internet-property-stream
.wsdl,text/xml
.disco,text/xml
.xsd,text/xml
.wbmp,image/vnd.wap.wbmp
.png,image/png
.pnz,image/png
.smd,audio/x-smd
.smz,audio/x-smd
.smx,audio/x-smd

 

分享到:
评论

相关推荐

    Struts2 文件上传之文件类型 allowedTypes.txt

    ### Struts2 文件上传之文件类型 allowedTypes.txt 在探讨Struts2框架中的文件上传功能时,一个重要的概念就是如何通过`allowedTypes`来限制上传文件的类型。这对于确保系统的安全性和提高用户体验至关重要。 ####...

    struts2文件上传,一直报类型不允许的问题

    Struts2 文件上传时遇到“类型不允许的问题”通常与文件扩展名验证有关,这涉及到Struts2框架的安全配置。在Struts2中,为了防止恶意用户上传不安全的文件(如脚本或可执行文件),系统会设定允许上传的文件类型。当...

    struts2_上传allowedTypes_类型

    在Struts2框架中,文件上传功能是常见的需求,而`allowedTypes`属性则是用来限制上传文件的类型。这个属性用于设置允许用户上传的文件的MIME类型,以确保安全性和合规性。以下将详细介绍Struts2中`allowedTypes`的...

    struts2 allowedTypes

    总而言之,`allowedTypes`是Struts2框架中用于控制文件上传安全性的关键配置,它通过限制允许上传的文件类型,有助于防止潜在的安全威胁。正确配置和使用`allowedTypes`可以提高应用的安全性和用户体验。

    struts2文件上传

    Struts2 文件上传是Web开发中的一个重要功能,它允许用户从他们的本地计算机向服务器传输文件。在Struts2框架中,文件上传是通过特定的拦截器实现的,这些拦截器处理了文件上传请求并提供了安全性和大小限制。下面将...

    struts2文件上传源码和步骤

    在 Struts2 中,文件上传功能是通过特定的拦截器(`FileUploadInterceptor`)来实现的。以下是对标题和描述中所述知识点的详细解释: 1. **文件上传原理**: 文件上传的本质是客户端浏览器将本地文件以二进制流的...

    Struts2文件上传程序示例

    Struts2文件上传程序是一个典型的企业级Web应用开发中的功能,它允许用户通过网页将本地文件上传到服务器。Struts2作为一款强大的MVC(Model-View-Controller)框架,提供了丰富的功能支持,包括文件上传。这个示例...

    java文件上传,Struts2文件上传,demo下载

    在Struts2中,文件上传功能是通过Struts2的核心拦截器`FileUploadInterceptor`来实现的。 首先,我们需要理解Struts2文件上传的基本流程: 1. 用户在前端页面通过表单提交包含文件的请求。 2. Struts2拦截器`...

    在Struts 2中实现文件上传

    此外,使用 `&lt;s:file&gt;` 标签将文件上传控件与 Action 中的某个字段(如 `myFile`)绑定,这样 Struts 2 就知道如何处理文件上传请求。 下面是一个简单的 `FileUpload.jsp` 示例: ```jsp ; charset=utf-8" ...

    Struts2文件上传

    在Struts2中实现文件上传是常见的需求,比如上传头像或文档。本篇文章将详细讲解如何利用Struts2框架来实现头像上传功能。 首先,我们需要在Struts2配置文件(struts.xml)中添加相关的action配置,以便处理文件...

    struts2文件上传,文件大小设置

    Struts2是一个流行的Java web框架,它提供了丰富的功能来处理用户请求,包括文件上传操作。在实际应用中,为了防止恶意用户上传过大的文件导致服务器资源耗尽,我们需要对文件上传的大小进行限制。本篇将详细介绍...

    struts2实现的文件上传(带文件类型和大小大小验证的)

    在这个"struts2实现的文件上传(带文件类型和大小验证的)"示例中,我们将深入探讨如何在Struts2中实现这一功能。 首先,我们需要在Struts2的配置文件(struts.xml)中添加一个或多个action配置,用于处理文件上传...

    Struts2实现文件上传

    在Struts2文件上传中,通常会有一个成员变量用于存储上传文件的MIME类型,这个变量的名称应该是`uploadContentType`而不是`uploadContextType`。尽管这个错误并不会导致程序无法运行,但修正它能提高代码的可读性和...

    struts 2文件上传

    在Struts 2中,文件上传功能是通过使用Struts 2的插件机制来实现的,这使得开发者能够方便地处理用户上传的文件。下面将详细讨论Struts 2文件上传的相关知识点。 ### 1. Struts 2文件上传原理 文件上传是基于HTTP...

    实现struts2的文件上传文件功能

    在Struts2中,实现文件上传功能是一项常见的需求,它允许用户通过Web界面上传文件到服务器。以下是对该主题的详细解释: 1. **Struts2文件上传原理** Struts2使用Apache的Commons FileUpload库来处理文件上传。这...

    struts2s上传文件

    在Struts2中,文件上传功能是一项常用的功能,允许用户通过Web表单上传文件到服务器。本篇将深入探讨Struts2中的文件上传机制、步骤以及常见问题。 首先,我们要理解文件上传的基本原理。在Web应用中,文件上传通常...

    Struts2实现文件上传功能

    在Struts2中,文件上传是一个常见的需求,尤其在用户需要提交表单并附带文件时。下面将详细阐述如何使用Struts2来实现文件上传功能。 1. **Struts2文件上传组件** Struts2框架集成了一个名为`struts2-convention-...

    struts2文件上传总结

    Struts2 文件上传是Java Web开发中的常见操作,主要用于处理用户通过表单上传的文件。在Struts2框架中,文件上传涉及到多个步骤和配置,包括表单设计、Action类的定义、拦截器的配置以及错误处理。以下是对Struts2...

    Struts2文件上传(二) 深入FileUploadInterceptor

    深入理解Struts2的FileUploadInterceptor,可以让我们更好地控制文件上传的过程,包括文件类型检查、大小限制、错误处理等。此外,还可以通过自定义拦截器扩展其功能,满足特定的业务需求。 总的来说,Struts2的...

Global site tag (gtag.js) - Google Analytics