java - 通过jsp错误生成从服务器获取的docx文件
问题描述
我正在尝试使用 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");
因为您的文件类型是 doc x。
请参阅此处的microsoft 文档。
推荐阅读
- windows - Bluestacks 作为 Android 模拟器 - 运行应用程序时出错
- javascript - 将动态值与逗号分隔的属性值进行比较
- javascript - 为什么这段代码不替换每个单词的第一个字母?
- ipc - 简单的进程间通信
- azure-devops - 如何为 Azure DevOps SSH 任务转义分号 (;) 字符?
- powershell - 创建新 AD 用户的脚本失败
- sql-server - SQL Pivot 作为子查询
- php - JSON - 使用 php 按日期对值求和
- html - 是否可以将自定义元素与 .Net Web Forms 控件一起使用?
- java - 如何从我的活动中的另一个活动中读取方法代码?