struts2

  1. IE下载Office2007文件时在下载对话框中变成ZIP文件问题的解决


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



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

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

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

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

  12. .asx,video/x-ms-asf
  13. .xml,text/xml
  14. .tsv,text/tab-separated-values
  15. .ra,audio/x-pn-realaudio
  16. .sv4crc,application/x-sv4crc
  17. .spc,application/x-pkcs7-certificates
  18. .pmc,application/x-perfmon
  19. .lit,application/x-ms-reader
  20. .crd,application/x-mscardfile
  21. .isp,application/x-internet-signup
  22. .wmlsc,application/vnd.wap.wmlscriptc
  23. .vst,application/vnd.visio
  24. .xlam,application/vnd.ms-excel.addin.macroEnabled.12
  25. .ttf,application/octet-stream
  26. .pfm,application/octet-stream
  27. .csv,application/octet-stream
  28. .aaf,application/octet-stream
  29. .one,application/onenote
  30. .hta,application/hta
  31. .atom,application/atom+xml
  32. .323,text/h323
  33. .mhtml,message/rfc822
  34. .midi,audio/mid
  35. .p7r,application/x-pkcs7-certreqresp
  36. .mny,application/x-msmoney
  37. .clp,application/x-msclip
  38. .vsd,application/vnd.visio
  39. .lpk,application/octet-stream
  40. .bin,application/octet-stream
  41. .onetoc,application/onenote
  42. .x,application/directx
  43. .wvx,video/x-ms-wvx
  44. .vcf,text/x-vcard
  45. .htc,text/x-component
  46. .htt,text/webviewhtml
  47. .h,text/plain
  48. .mht,message/rfc822
  49. .mid,audio/mid
  50. .p7b,application/x-pkcs7-certificates
  51. .gz,application/x-gzip
  52. .dvi,application/x-dvi
  53. .cpio,application/x-cpio
  54. .vdx,application/vnd.ms-visio.viewer
  55. .sldm,application/vnd.ms-powerpoint.slide.macroEnabled.12
  56. .xlm,application/vnd.ms-excel
  57. .fdf,application/vnd.fdf
  58. .setreg,application/set-registration-initiation
  59. .eps,application/postscript
  60. .p7s,application/pkcs7-signature
  61. .toc,application/octet-stream
  62. .mdp,application/octet-stream
  63. .ics,application/octet-stream
  64. .chm,application/octet-stream
  65. .asi,application/octet-stream
  66. .afm,application/octet-stream
  67. .evy,application/envoy
  68. .wmp,video/x-ms-wmp
  69. .qt,video/quicktime
  70. .mpv2,video/mpeg
  71. .xslt,text/xml
  72. .etx,text/x-setext
  73. .cod,image/cis-cod
  74. .snd,audio/basic
  75. .au,audio/basic
  76. .man,application/x-troff-man
  77. .qtl,application/x-quicktimeplayer
  78. .pmw,application/x-perfmon
  79. .class,application/x-java-applet
  80. .iii,application/x-iphone
  81. .csh,application/x-csh
  82. .z,application/x-compress
  83. .vtx,application/vnd.visio
  84. .vsw,application/vnd.visio
  85. .wps,application/vnd.ms-works
  86. .potx,application/vnd.openxmlformats-officedocument.presentationml.template
  87. .ps,application/postscript
  88. .p7c,application/pkcs7-mime
  89. .thn,application/octet-stream
  90. .mso,application/octet-stream
  91. .dot,application/msword
  92. .doc,application/msword
  93. .sgml,text/sgml
  94. .nws,message/rfc822
  95. .pbm,image/x-portable-bitmap
  96. .ief,image/ief
  97. .wav,audio/wav
  98. .texi,application/x-texinfo
  99. .mvb,application/x-msmediaview
  100. .hdf,application/x-hdf
  101. .vsx,application/vnd.visio
  102. .dotm,application/vnd.ms-word.template.macroEnabled.12
  103. .docm,application/vnd.ms-word.document.macroEnabled.12
  104. .pptx,application/vnd.openxmlformats-officedocument.presentationml.presentation
  105. .psm,application/octet-stream
  106. .java,application/octet-stream
  107. .eot,application/octet-stream
  108. .jar,application/java-archive
  109. .mpeg,video/mpeg
  110. .xsf,text/xml
  111. .map,text/plain
  112. .uls,text/iuls
  113. .rf,image/vnd.rn-realflash
  114. .m3u,audio/x-mpegurl
  115. .wma,audio/x-ms-wma
  116. .aifc,audio/aiff
  117. .mdb,application/x-msaccess
  118. .mvc,application/x-miva-compiled
  119. .stl,application/vnd.ms-pki.stl
  120. .ppsx,application/vnd.openxmlformats-officedocument.presentationml.slideshow
  121. .xlsb,application/vnd.ms-excel.sheet.binary.macroEnabled.12
  122. .setpay,application/set-payment-initiation
  123. .prm,application/octet-stream
  124. .mix,application/octet-stream
  125. .lzh,application/octet-stream
  126. .hhk,application/octet-stream
  127. .onepkg,application/onenote
  128. .xaf,x-world/x-vrml
  129. .flr,x-world/x-vrml
  130. .IVF,video/x-ivf
  131. .cnf,text/plain
  132. .asm,text/plain
  133. .tiff,image/tiff
  134. .wax,audio/x-ms-wax
  135. .ms,application/x-troff-ms
  136. .tcl,application/x-tcl
  137. .shar,application/x-shar
  138. .sh,application/x-sh
  139. .nc,application/x-netcdf
  140. .hlp,application/winhlp
  141. .oda,application/oda
  142. .pfb,application/octet-stream
  143. .fla,application/octet-stream
  144. .wm,video/x-ms-wm
  145. .rgb,image/x-rgb
  146. .ppm,image/x-portable-pixmap
  147. .ram,audio/x-pn-realaudio
  148. .sit,application/x-stuffit
  149. .dir,application/x-director
  150. .mpp,application/vnd.ms-project
  151. .xla,application/vnd.ms-excel
  152. .ssm,application/streamingmedia
  153. .axs,application/olescript
  154. .ods,application/oleobject
  155. .psp,application/octet-stream
  156. .jpb,application/octet-stream
  157. .wrz,x-world/x-vrml
  158. .m1v,video/mpeg
  159. .mno,text/xml
  160. .cmx,image/x-cmx
  161. .jpeg,image/jpeg
  162. .dib,image/bmp
  163. .rmi,audio/mid
  164. .aiff,audio/aiff
  165. .wmd,application/x-ms-wmd
  166. .wri,application/x-mswrite
  167. .pub,application/x-mspublisher
  168. .ins,application/x-internet-signup
  169. .wks,application/vnd.ms-works
  170. .xls,application/vnd.ms-excel
  171. .ai,application/postscript
  172. .crl,application/pkix-crl
  173. .qxd,application/octet-stream
  174. .dwp,application/octet-stream
  175. .xof,x-world/x-vrml
  176. .wmv,video/x-ms-wmv
  177. .nsc,video/x-ms-asf
  178. .mpa,video/mpeg
  179. .pnm,image/x-portable-anymap
  180. .rpm,audio/x-pn-realaudio-plugin
  181. .aif,audio/x-aiff
  182. .me,application/x-troff-me
  183. .pml,application/x-perfmon
  184. .trm,application/x-msterminal
  185. .m13,application/x-msmediaview
  186. .js,application/x-javascript
  187. .dxr,application/x-director
  188. .potm,application/vnd.ms-powerpoint.template.macroEnabled.12
  189. .xltx,application/vnd.openxmlformats-officedocument.spreadsheetml.template
  190. .xlt,application/vnd.ms-excel
  191. .xlc,application/vnd.ms-excel
  192. .p10,application/pkcs10
  193. .smi,application/octet-stream
  194. .sea,application/octet-stream
  195. .hqx,application/mac-binhex40
  196. .spl,application/futuresplash
  197. .movie,video/x-sgi-movie
  198. .lsf,video/x-la-asf
  199. .txt,text/plain
  200. .jfif,image/pjpeg
  201. .jpe,image/jpeg
  202. .zip,application/x-zip-compressed
  203. .wmf,application/x-msmetafile
  204. .m14,application/x-msmediaview
  205. .latex,application/x-latex
  206. .wcm,application/vnd.ms-works
  207. .pptm,application/vnd.ms-powerpoint.presentation.macroEnabled.12
  208. .xlsx,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  209. .hhp,application/octet-stream
  210. .aca,application/octet-stream
  211. .accdb,application/msaccess
  212. .jcz,application/liquidmotion
  213. .wrl,x-world/x-vrml
  214. .wmx,video/x-ms-wmx
  215. .asr,video/x-ms-asf
  216. .lsx,video/x-la-asf
  217. .xsl,text/xml
  218. .html,text/html
  219. .tif,image/tiff
  220. .der,application/x-x509-ca-cert
  221. .pfx,application/x-pkcs12
  222. .p12,application/x-pkcs12
  223. .ppsm,application/vnd.ms-powerpoint.slideshow.macroEnabled.12
  224. .cur,application/octet-stream
  225. .accdt,application/msaccess
  226. .hdml,text/x-hdml
  227. .htm,text/html
  228. .xbm,image/x-xbitmap
  229. .jpg,image/jpeg
  230. .texinfo,application/x-texinfo
  231. .ppam,application/vnd.ms-powerpoint.addin.macroEnabled.12
  232. .xlw,application/vnd.ms-excel
  233. .rm,application/vnd.rn-realmedia

你可能感兴趣的:(struts2)