将Content-Disposition设置为内联.docx / .doc(仍在所有浏览器中下载)

时间:2016-10-03 06:39:31

标签: servlets browser download inline docx

我在google上搜索了它,但没有得到相应的正确解释 我编写了以下代码来在浏览器中打开文档。我无法出于某种原因下载该文档,因此我设置了以下响应标头。我可以在浏览器中查看以下格式:

  • pdf
  • xml
  • text
  • jpg
  • PNG

(但 NOT DOC或DOCX

    String headerKey = "Content-Disposition";
    String headerValue = String.format("inline; filename=\"%s\"", downloadFile.getName());
    response.setHeader(headerKey, headerValue);

    // get output stream of the response
    OutputStream outStream = response.getOutputStream();
    outStream.write(buffer, 0, bytesRead);
    outStream.flush();
    response.flushBuffer();

请帮帮我。我只想在浏览器中打开文档。

修改

即使对于doc和docx格式,Servlet也能完美地读取MIME类型。 MS Word也安装在我的机器上,而.doc和.docx类型映射到Word

0 个答案:

没有答案
相关问题