无法从servlet打开文件

时间:2014-03-05 15:00:19

标签: file servlets internet-explorer-8

我正在尝试从IE中的servlet打开一个pdf文件。它给出的错误为com.ibm.wsspi.webcontainer.ClosedConnectionException: OutputStream encountered error during write

下面的

是代码段

File file = new File("Desktop\\Workflow\\123456.pdf");
if(!file.exists()) {
    throw new ServletException("File doesn't exists on server.");
}
System.out.println("File location on server::"+file.getAbsolutePath());
InputStream fis = new FileInputStream(file);
String mimeType = ctx.getMimeType(file.getAbsolutePath());
response.setContentType(mimeType != null? mimeType:"application/octet-stream");
response.setContentLength((int) file.length());
response.setHeader("Content-Disposition", "attachment; filename=\"123456.pdf\"");
ServletOutputStream os = response.getOutputStream();
byte[] bufferData = new byte[1024];
int read=0;
while((read = fis.read(bufferData))!= -1) {
    System.out.println("read::"+read);    
    os.write(bufferData, 0, read);
}
os.flush();
os.close();
fis.close();

我在第os.write(bufferData, 0, read);

收到错误

在Mozilla中我没有收到任何错误,但文件也没有在这里打开

0 个答案:

没有答案