求助大虾:当下载页面出现后,点击“保存”没有任何问题,但是点击“打开”却要点击两次才能打开,但是.xls文档只需要点击一次就可以打开,对于.txt/.img/.jpg/.gig/.sql/.properties等文件却要点击两次才能打开?
代码如下:
String attachID = request.getParameter("attachID"); attachmentMode = attachmentAdapter.getAttachment(attachID); byte[] content = attachmentMode.getAttachContent(); String fileName = attachmentMode.getFileName(); int fileSize = (new Long(attachmentMode.getAttachSize())).intValue(); java.io.ByteArrayInputStream byteInputStream =
new java.io.ByteArrayInputStream(content); javax.servlet.ServletOutputStream out= response.getOutputStream(); response.setHeader("Content-Disposition", "attachment;filename=\""+fileName+"\""); byte buff[] = new byte[fileSize]; while(byteInputStream.read(buff)!=-1){
out.write(buff);
} out.flush(); byteInputStream.close(); out.close();
代码如下:
String attachID = request.getParameter("attachID"); attachmentMode = attachmentAdapter.getAttachment(attachID); byte[] content = attachmentMode.getAttachContent(); String fileName = attachmentMode.getFileName(); int fileSize = (new Long(attachmentMode.getAttachSize())).intValue(); java.io.ByteArrayInputStream byteInputStream =
new java.io.ByteArrayInputStream(content); javax.servlet.ServletOutputStream out= response.getOutputStream(); response.setHeader("Content-Disposition", "attachment;filename=\""+fileName+"\""); byte buff[] = new byte[fileSize]; while(byteInputStream.read(buff)!=-1){
out.write(buff);
} out.flush(); byteInputStream.close(); out.close();
FileInputStream fis = new FileInputStream(strDownloadFileName);
byte[] b = new byte[fis.available()];
fis.read(b);
fis.close();
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment; filename="
+ toISO8859_1(strFileName));
OutputStream out = response.getOutputStream();
out.write(b, 0, b.length);
out.close();