>我正在尝试返回一个使用 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 宣布了我这个 错误 1 错误 2
单击确定后我仍然可以阅读内容,但我不知道问题是什么,我该如何解决? 我正在使用Word 2016,服务器是WebSphere V9
而不是
response.setContentType("application/ms-word");
用
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
因为您的文件类型是文档X。
请参阅此处的微软文档。