寻求*.docx,*.xlsx,*.pptx文件下载后变成.zip文件的解决办法
网上有说在web.xml中增加如下代码就可以了,但我添加后还是不行.
  <mime-mapping>
   <extension>docx</extension>
   <mime-type>application/vnd.openxmlformats-officedocument.wordprocessingml.document</mime-type>
  </mime-mapping>
  <mime-mapping>
   <extension>xlsx</extension>
   <mime-type>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</mime-type>
  </mime-mapping>
  <mime-mapping>
   <extension>pptx</extension>
   <mime-type>application/vnd.openxmlformats-officedocument.presentationml.presentation</mime-type>
  </mime-mapping>
请大虾帮忙!

解决方案 »

  1.   

    非得配置呀,用个serlvet直接通过java的API把文件打成zip包然后下载!
      

  2.   

    package com.sitinspring.zip.test;
    import java.io.File;
    import java.io.IOException;
    import org.apache.tools.zip.ZipEntry;
    import org.apache.tools.zip.ZipOutputStream;
    import de.schlichtherle.io.FileInputStream;
    import de.schlichtherle.io.FileOutputStream;
    public class MoreZip {
     public static void main(String[] args) { 
      File[] f={new File("D:/中文/我们.txt"),new File("D:/中文/他们.txt"),new File("D:/中文/你们.txt")};
      MoreZip.ZipFiles(f, new File("D:/你我他.zip"));
     }
    /**
       * 压缩文件
       * @param srcfile File[]  需要压缩的文件列表
       * @param zipfile File    压缩后的文件
       */
     public static void ZipFiles(java.io.File[] srcfile, java.io.File zipfile) {
         byte[] buf = new byte[1024];
         try {
           // Create the ZIP file
           ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile));
           // Compress the files
           for (int i = 0; i < srcfile.length; i++) {
             FileInputStream in = new FileInputStream(srcfile[i]);
             // Add ZIP entry to output stream.
             out.putNextEntry(new ZipEntry(srcfile[i].getName()));
             // Transfer bytes from the file to the ZIP file
             int len;
             while ( (len = in.read(buf)) > 0) {
               out.write(buf, 0, len);
             }
             // Complete the entry
             out.closeEntry();
             in.close();
           }
           // Complete the ZIP file
           out.close();
           System.out.println("压缩完成.");
         }
         catch (IOException e) {
           e.printStackTrace();
         }
       }
      

  3.   

    谢谢楼上两位的答复.
    可能是我说的不够清楚,我上传的是*.docx,*.xlsx,*.pptx文件,但下载后就变成了*.zip文件
    我不希望他变成*.zip文件,希望下载和上传的文件格式保持一致.
      

  4.   

    在servlet里增加response.setContentType("application/msexcel");
    response.setHeader("Content-Disposition", " filename=report.xls");
      
      

  5.   

    我也碰到这种问题,xls,ppt,doc格式没有问题,遇到07版的用链接下载就会自动保存成.zip或者.rar格式,郁闷死。后来用各种浏览器试了一下,好像只在IE7下出问题,IE6,IE8,FireFox都没问题。
      

  6.   

    tomcat容器,在conf/web.xml中增加楼主贴出来的那些代码,就OK了
    其他的还没试过