我正在尝试从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中我没有收到任何错误,但文件也没有在这里打开