从db下载文件时已获得Writer

时间:2019-03-27 05:44:13

标签: java1.4

我正在使用WebSphere,并且从数据库下载文件时出现异常“已获取作家”。函数下载内容为空的文件。我需要下载包含内容的文件。控制器中的response.getOutputStream()行之后,该代码不起作用。

private void downloadAttachement(String RefId, String fileId, HttpServletRequest req, HttpServletResponse resp) {
    try {
        FileManger fileManager = new FileManger();
        Blob FileData = fileManager.DownloadAttachment(RefId, fileId);
        System.out.println("inside down Blob  " + FileData.toString());
        String fileName = fileManager.getFileName(RefId, fileId);
        System.out.println("inside down fileName  " + fileName);
        if (FileData != null) {
            ApplicationDebugger.print("downloadAttachement 000000");
            int size = (int) FileData.length();
            byte buffer[] = FileData.getBytes(1, size);
            resp.setHeader("Conection", "keep-alive");
            resp.setContentType("multipart/form-data"); // Or whatever is correct multipart/form-data
            resp.setHeader("Accept-Ranges", "bytes");
            resp.setHeader("Content-Disposition", "attachment; filename=" + fileName);
            ApplicationDebugger.print("downloadAttachement 000001 " + resp);
            ServletOutputStream stream = resp.getOutputStream();
            ApplicationDebugger.print("downloadAttachement 000005 stream ");
            int sent = 0;
            stream.write(buffer);
            stream.flush();
        }
    } catch (IOException ioex) {
        ApplicationDebugger.print("InstructionsAction: downloadAttachement IOException : " + ioex.getMessage());
    } catch (Exception ex) {
        ApplicationDebugger.print("InstructionsAction: downloadAttachement Exception : " + ex.getMessage());
    }
}

我需要下载内容文件。但是它会下载空文件(txt,img,html .....)。

0 个答案:

没有答案
相关问题