我想在线提供管理文件,而不是作为附件下载。 我根据文件类型界定了申请类型,但客户仍然试图下载。 我的守则是:
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();
}
}
如何造成这种情况,我如何解决这一问题?