我想内联提供 MS 文档,而不是通过附件提供它作为下载。我根据文档类型定义了应用程序 mime 类型,但客户端仍然尝试下载它。这是我的代码:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
InputStream is = null;
String fileName = "file.docx";
try {
java.io.File file = new java.io.File("C:/"+fileName);
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
byte[] bytes = new byte[in.available()];
in.read(bytes);
in.close();
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
response.addHeader("Content-Disposition", "inline;filename=\"" + fileName + "\"");
response.getOutputStream().write(bytes);
} catch (Exception e) {
e.printStackTrace();
}
}
这是如何引起的,我该如何解决?