使用Struts2下载文件并提示

时间:2016-07-28 19:22:39

标签: java google-chrome download struts2 http-headers

我正在使用Struts2下载文件。当我点击按钮下载文件时,文件会自动下载并在Excel中打开,而我希望它下载,当我右键单击它时,我应该可以打开或保存它。在IEFirefox中,我会打开一个窗口来打开或保存文件,但在Chrome中,文件文件会自动在Excel中打开。有没有办法在Chrome FirefoxIE

中加入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; }

动作

<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>

struts.xml中

#include <iostream>
#include <queue>

int main() {
    int tree[] = {5, 9, 11, 14, 18, 19, 21, 33, 17, 27};
    int size = 10;
    std::queue <int> q;
    q.push(0);
    bool flag = true;
    while(!q.empty()) {
        int x = q.front();
        q.pop();
        int left = 2*x+1, right = 2*x+2;  // 0-based indexing used here
        if(left < size) {    // check if left child exists or not.
            q.push(left);
          // check value at parent is less than child or not.
            if(tree[x] > tree[left]) {
                flag = false;
                break;
            }
        }
        if(right < size) {   // check whether right child exists or not.
            q.push(right);
            if(tree[x] > tree[right]) {  // check value of parent less than child.
                flag = false;
                break;
            }
        }
    }
    if(flag)
        std::cout << "It is minimum heap.\n";
    else
        std::cout << "Not a minimum heap.\n";
    return 0;
}

1 个答案:

答案 0 :(得分:1)

提示询问是使用桌面应用程序打开文件还是保存文件是由contentDisposition HTTP标头设置为attachment(您已设置)。相反,inline会尝试使用浏览器插件打开文件,而不会询问任何内容。

也就是说,问题背后的原因是您(或有权访问您计算机的人)之前曾指示Chrome 始终打开此类型的文件,这就是为什么它没有&#39不再问你该怎么做了:

enter image description here


解决方法是从设置中清除此选项


自定义和控制Google Chrome 设置 +显示高级设置 清除自动开启设置


enter image description here