1. 程式人生 > >解決IE下載DOCX檔案時自動變為ZIP的方法

解決IE下載DOCX檔案時自動變為ZIP的方法

在公司開發中遇到使用javaScript 中的windo.open(url)方法進行開啟生成了zip包,並不能進行直接開啟。經過從各種方式查詢並解決,已分享出來供大家一起學習用!

1。首先在工程中的 web.xml 檔案中要進行配置一下:
<mime-mapping>
<extension>xlsx</extension>
<mime-type>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</mime-type>
</mime-mapping>
<mime-mapping>
<extension>docx</extension>
<mime-type>application/vnd.openxmlformats-officedocument.wordprocessingml.document</mime-type>
</mime-mapping>

2。找到對應的mime.types 屬性檔案,將不同的type 進行新增:我用的是 sun -one application Server 伺服器;
我的mime.type 檔案中的內容如下:
#--Sun Microsystems Inc. MIME Information
# Do not delete the above line. It is used to identify the file type.
#
# Copyright (c) 2002 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#

type=application/octet-stream exts=bin
type=application/astound exts=asd,asn
type=application/fastman exts=lcc
type=application/java-archive exts=jar
type=application/java-serialized-object exts=ser
type=application/java-vm exts=class
type=application/mac-binhex40 exts=hqx
type=application/x-stuffit exts=sit
type=application/mbedlet exts=mbd
type=application/msword exts=doc,dot,wiz,rtf
type=application/oda exts=oda
type=application/pdf exts=pdf
type=application/postscript exts=ai,eps,ps
type=application/studiom exts=smp
type=application/timbuktu exts=tbt
type=application/vnd.ms-excel exts=xls,xlw,xla,xlc,xlm,xlt
type=application/vnd.ms-powerpoint exts=ppt,pps,pot
type=application/vnd.ms-project exts=mpp
type=application/winhlp exts=hlp
type=application/x-javascript exts=js
type=application/x-javascript;charset=UTF-8 exts=jsu
type=application/x-java-jnlp-file exts=jnlp
type=application/x-aim exts=aim
type=application/x-asap exts=asp
type=application/x-csh exts=csh
type=application/x-dvi exts=dvi
type=application/x-earthtime exts=etc
type=application/x-envoy exts=evy
type=application/x-gtar exts=gtar
type=application/x-cpio exts=cpio
type=application/x-hdf exts=hdf
type=application/x-latex exts=latex
type=application/x-javascript-config exts=jsc
type=application/x-maker exts=fm
type=application/x-mif exts=mif,mi
type=application/x-mocha exts=mocha,moc
type=application/x-msaccess exts=mdb
type=application/x-mscardfile exts=crd
type=application/x-msclip exts=clp
type=application/x-msmediaview exts=m13,m14
type=application/x-msmetafile exts=wmf
type=application/x-msmoney exts=mny
type=application/x-mspublisher exts=pub
type=application/x-msschedule exts=scd
type=application/x-msterminal exts=trm
type=application/x-mswrite exts=wri
type=application/x-NET-Install exts=ins
type=application/x-netcdf exts=nc,cdf
type=application/x-ns-proxy-autoconfig exts=proxy
type=application/x-salsa exts=slc
type=application/x-sh exts=sh
type=application/x-shar exts=shar
type=application/x-sprite exts=spr,sprite
type=application/x-tar exts=tar
type=application/x-tcl exts=tcl
type=application/x-perl exts=pl
type=application/x-tex exts=tex
type=application/x-texinfo exts=texinfo,texi
type=application/x-timbuktu exts=tbp
type=application/x-tkined exts=tki,tkined
type=application/x-troff-man exts=man
type=application/x-troff-me exts=me
type=application/x-troff-ms exts=ms
type=application/x-troff exts=t,tr,roff
type=application/x-wais-source exts=src
type=application/zip exts=zip
type=application/pre-encrypted exts=enc
type=application/x-pkcs7-crl exts=crl
type=application/x-fortezza-ckl exts=ckl
type=application/xml-dtd exts=dtd

type=audio/basic exts=au,snd
type=audio/echospeech exts=es,esl
type=audio/midi exts=midi,mid
type=audio/x-aiff exts=aif,aiff,aifc
type=audio/x-wav exts=wav
type=audio/x-pn-realaudio exts=ra,ram
type=audio/x-pac exts=pac
type=audio/x-epac exts=pae
type=audio/x-liveaudio exts=lam

type=drawing/x-dwf exts=dwf

type=image/fif exts=fif
type=image/x-icon exts=ico
type=image/gif exts=gif
type=image/ief exts=ief
type=image/ifs exts=ifs
type=image/jpeg exts=jpeg,jpg,jpe,jfif,pjpeg,pjp
type=image/png exts=png
type=image/tiff exts=tiff,tif
type=image/vnd exts=dwg,svf
type=image/wavelet exts=wi
type=image/bmp exts=bmp
type=image/x-photo-cd exts=pcd
type=image/x-cmu-raster exts=ras
type=image/x-portable-anymap exts=pnm
type=image/x-portable-bitmap exts=pbm
type=image/x-portable-graymap exts=pgm
type=image/x-portable-pixmap exts=ppm
type=image/x-rgb exts=rgb
type=image/x-xbitmap exts=xbm
type=image/x-xpixmap exts=xpm
type=image/x-xwindowdump exts=xwd

type=text/css exts=css
type=text/html exts=htm,html
type=text/plain exts=txt
type=text/richtext exts=rtx
type=text/tab-separated-values exts=tsv
type=text/x-setext exts=etx
type=text/x-speech exts=talk
type=text/xml exts=xml
type=text/xul exts=xul

type=video/isivideo exts=fvi
type=video/mpeg exts=mpeg,mpg,mpe,mpv,vbs,mpegv
type=video/x-mpeg2 exts=mpv2,mp2v
type=video/msvideo exts=avi
type=video/quicktime exts=qt,mov,moov
type=video/vivo exts=viv,vivo
type=video/wavelet exts=wv
type=video/x-sgi-movie exts=movie

type=x-world/x-svr exts=svr
type=x-world/x-vrml exts=wrl
type=x-world/x-vrt exts=vrt

type=x-conference/x-cooltalk exts=ice

enc=x-gzip exts=gz
enc=x-compress exts=z
enc=x-uuencode exts=uu,uue

type=magnus-internal/imagemap exts=map
type=magnus-internal/parsed-html exts=shtml
type=magnus-internal/cgi exts=cgi,exe,bat

type=application/x-x509-ca-cert exts=cacert
type=application/x-x509-server-cert exts=scert
type=application/x-x509-user-cert exts=ucert
type=application/x-x509-email-cert exts=ecert

type=application/vnd.openxmlformats-officedocument.wordprocessingml.document.docx
exts=docx
type=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.xlsx exts=xlsx



修復很簡單,只需要在Apache的httpd.conf裡新增額外的MIME types資訊然後重啟即可。
以下是office2007 對應個格式:
application/vnd.ms-word.document.macroEnabled.12 .docm

application/vnd.openxmlformats .docx .pptx .xlsx

application/vnd.openxmlformats-officedocument.presentationml.presentation .pptx

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet .xlsx

application/vnd.openxmlformats-officedocument.wordprocessingml.document .docx

application/vnd.ms-word.template.macroEnabled.12 .dotm

application/vnd.openxmlformats-officedocument.wordprocessingml.template .dotx

application/vnd.ms-powerpoint.template.macroEnabled.12 .potm

application/vnd.openxmlformats-officedocument.presentationml.template .potx

application/vnd.ms-powerpoint.addin.macroEnabled.12 .ppam

application/vnd.ms-powerpoint.slideshow.macroEnabled.12 .ppsm

application/vnd.openxmlformats-officedocument.presentationml.slideshow .ppsx

application/vnd.ms-powerpoint.presentation.macroEnabled.12 .pptm

application/vnd.ms-excel.addin.macroEnabled.12 .xlam

application/vnd.ms-excel.sheet.binary.macroEnabled.12 .xlsb

application/vnd.ms-excel.sheet.macroEnabled.12 .xlsm

application/vnd.ms-excel .xlt .xla

application/vnd.openxmlformats-officedocument.spreadsheetml.template .xltx

application/vnd.ms-excel.template.macroEnabled.12 .xltm

application/vnd.ms-xpsdocument .xps

application/application/vnd.ms-powerpoint .ppt .pot .pps .ppa

application/msword .doc .dot

方法二:將下載下來的.zip 直接改為 .docx 等也可以將其開啟。(不推薦)