在文件下载的时候 遇到这个问题。
关键代码如下:
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
OutputStream fos = null;
InputStream fis = null;
fis = new FileInputStream(filePath); bis = new BufferedInputStream(fis);
fos = response.getOutputStream();
bos = new BufferedOutputStream(fos); int bytesRead = 0;
byte[] buffer = new byte[5 * 1024];
//在这里出现错误
while ((bytesRead = bis.read(buffer)) != -1) {
bos.write(buffer, 0, bytesRead);
}
finally {
try { if (bos != null)
bos.close();
if (fos != null)
fos.close();
if (fis != null)
fis.close();
if (bis != null)
bis.close();
} catch (IOException ee) {
throw ee;
}
}
这是什么原因呢,在网上搜了很久,也没有一个好使的办法,麻烦哪位大虾帮忙解答下下。
关键代码如下:
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
OutputStream fos = null;
InputStream fis = null;
fis = new FileInputStream(filePath); bis = new BufferedInputStream(fis);
fos = response.getOutputStream();
bos = new BufferedOutputStream(fos); int bytesRead = 0;
byte[] buffer = new byte[5 * 1024];
//在这里出现错误
while ((bytesRead = bis.read(buffer)) != -1) {
bos.write(buffer, 0, bytesRead);
}
finally {
try { if (bos != null)
bos.close();
if (fos != null)
fos.close();
if (fis != null)
fis.close();
if (bis != null)
bis.close();
} catch (IOException ee) {
throw ee;
}
}
这是什么原因呢,在网上搜了很久,也没有一个好使的办法,麻烦哪位大虾帮忙解答下下。
如例:
HttpServletResponse response = ServletActionContext.getResponse();
PrintWriter writer = response.getWriter();
writer.close();
java.lang.IllegalStateException: getOutputStream() has already been called for this response。但是我只有在这里一处用到,其他地方都没有用到。为什么还报has already been called?
原因是我连续两次使用了上面的程序,但每一次都有关闭。为什么还报has already bean called?
out=pageContext.pushBody();
这个out 指什么,response.getWriter?加在什么位置 程序在 Action里面的。
当抛出ClientAbortException的时候,最好检查下客户端是否正常接收文件。我的程序就是因为在传给客户端文件大小的时候出错,造成的这个错误。
我的点点困难和大家分享,希望对需要的人有帮助。