使用Struts2下载文件并提示
问题描述:
我正在使用Struts2
下载文件。当我点击按钮下载文件时,文件会自行下载并在Excel中打开,而不是我希望它下载,当我右键点击它时,我应该可以打开或保存它。在IE
和Firefox
我得到一个窗口来打开或保存文件,但在Chrome
文件文件本身打开在Excel中。有没有办法把它在Chrome
就像Firefox
和IE
使用Struts2下载文件并提示
行动
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>
你是真棒安德烈。你明白我的问题,没有任何进一步的调查,你回答了我正在寻找的东西。我被告知这是一个浏览器行为,但没有人知道如何解决它。再次感谢你。 – Jaykumar