【问题标题】:generate docx file got from server through jsp error通过jsp错误生成从服务器获取的docx文件
【发布时间】:2018-11-15 20:07:23
【问题描述】:

我正在尝试返回我使用 jsp 从服务器获取的 docx 文件

if(pathfile != null){
        String mimetype=application.getMimeType(pathfile);
        System.out.println("mimeType: "+ mimetype);
        response.setContentType("application/ms-word");     
        response.setHeader("Content-disposition", "attachment; filename=Resultfile.docx");

        File file = new File(pathfile);
        FileInputStream fileIn = new FileInputStream(file);
        //OutputStream output = response.getOutputStream();

        int i;   
        while ((i=fileIn.read()) != -1) {  
        out.write(i);   
      }   
      fileIn.close(); 

    }else{

        %> <div>Khong co file</div> <%

    }

但是当我尝试打开文件时,MSW 向我宣布了这一点 error 1 error 2

点击确定后我仍然可以阅读内容,但我不知道是什么问题,我该如何解决? 我用的是word 2016,服务器是websphere V9

【问题讨论】:

    标签: java jsp servlets jakarta-ee websphere


    【解决方案1】:

    代替

    response.setContentType("application/ms-word");
    

    使用

    response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
    

    因为您的文件类型是 docx

    参考微软文档here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 2017-09-01
      相关资源
      最近更新 更多