刷新下载zip文件后未加载JSP页面

时间:2019-11-04 13:51:19

标签: jsp jsf flush managed-bean

使用托管bean时,单击JSP上的一个按钮会导致一个Java文件,我将zip文件刷新到浏览器,并配置为在刷新后加载JSP页面。不会发生这种JSP文件加载。请帮助我。

以下是刷新zip文件的代码:

Vector receipts = new Vector();
    Connection connection = ReceiptsConnectionManager.getConnection();
    receipts = receiptsQuery.getReceiptsForDocument(m_trackingNo, connection);

    HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
    response.setHeader("Content-Disposition","attachment; filename=\"" + "myfile.zip" + "\"");
    response.setContentType("application/zip");

    ServletOutputStream baos = response.getOutputStream();
    ZipOutputStream zip = new ZipOutputStream(baos);
    for (int i = 0; i < receipts.size(); i++)
    {
        Receipt receipt = (Receipt)receipts.elementAt(i);
        byte[] receiptBytes = receiptsQuery.getReceipt(receipt.getReceiptId());
        String fileName = m_trackingNo + "." + receipt.getReceiptId() + "." + receipt.getReceiptType();
        ZipEntry zipEntry = new ZipEntry(fileName);
        zip.putNextEntry(zipEntry);
        zip.write(receiptBytes, 0, receiptBytes.length);
        zip.closeEntry();
    }
    zip.close();

    try{
        zip.flush();
        response.flushBuffer();
    }
    catch (IOException e){
        e.printStackTrace();        
    }
    finally{
        baos.close();
    }
    facesContext.getCurrentInstance().responseComplete();

    return "next";

这是faces-config.xml:

    <managed-bean>
    <managed-bean-name>downloadReceipts</managed-bean-name>
    <managed-bean-class>com.geac.extn.receipts.web.faces.DowloadReceiptsAction</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
        <property-name>forwards</property-name>
        <map-entries>
            <map-entry>
                <key>next</key>
                <value>goHomeOutCome</value>
            </map-entry>
        </map-entries>
    </managed-property>
</managed-bean> 

<navigation-case>       
        <from-outcome>goHomeOutCome</from-outcome>
        <to-view-id>/app/main.jsf</to-view-id>
</navigation-case>

在这种情况下,main.jsf没有加载,页面上显示“请求正在处理中”,没有错误消息。

0 个答案:

没有答案