我正在使用Struts2
下载文件。当我单击按钮下载文件时,文件将单独下载并在Excel中打开,而不是我要下载,当我右键单击该文件时,我应该可以打开或保存它。在IE
和Firefox
中,我有一个打开或保存文件的窗口,但是在Chrome
中,文件文件本身是在Excel中打开的。有什么办法可以像Chrome
和Firefox
一样在IE
中使用它吗?
行动
public String viewReport() throws Exception {
boolean returnReport;
inputStream = new FileInputStream(DOCUSIGN_REPORT_FILE);
try {
returnReport = validateRequest();
if (returnReport) {
intgList = this.generateViewIntegrationReportData(getESignUIConfig());
this.createCSVFile(intgList, DOCUSIGN_REPORT_FILE);
} else {
failureResponse(msgs, 400);
return null;
}
} catch (Exception e) {
e.printStackTrace();
msgs.add(new Message(ESignatureIntegrationMessageTypeEnum.MESSAGE_TYPE_ERROR,
UiIntegrationKeyConstants.UI_INTEGRATION_ERROR_CODE_500, UiIntegrationKeyConstants.UI_INTEGRATION_ERROR_TEXT_SERVICE_ERROR));
failureResponse(msgs, 500);
return null;
}
return UiIntegrationKeyConstants.REPORT_REPSONSE;
}
Struts.xml
<action name="*Integration" method="{1}" class="foo.bar.ESignatureIntegrationAction">
<result name="success" type="tiles">integrationView</result>
<result name="reportResponse" type="stream">
<param name="contentType">application/text/csv</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">
attachment;filename="DocuSignEnvelopeReport.csv"
</param>
<param name="bufferSize">4096</param>
</result>
</action>
最佳答案
通过设置为contentDisposition
(已设置)的attachment
HTTP标头给出询问是否使用桌面应用程序打开文件或保存文件的提示。相反,inline
会尝试使用浏览器插件打开文件,而不问任何问题。
也就是说,问题背后的原因是您(或有权访问您计算机的人)先前已指示Chrome始终打开此类文件,这就是为什么它不再询问您要做什么的原因:
解决方案是从设置中清除此选项
自定义和控制Google Chrome设置+显示高级设置清除自动打开的设置