對我的代碼允許用戶下載文件的任何評論。最佳做法response.getOutputStream
if(fileObject !=null)
response.setHeader("Content-disposition", "attachment; filename=\""+fileObject.getFilename()+"\"");
response.setContentType(fileObject.getFiletype());
response.setContentLength((int)fileObject.getFilesize().intValue());
try {
if(response !=null && response.getOutputStream() !=null &&fileObject!=null && fileObject.getBinData() !=null){
OutputStream out = response.getOutputStream();
out.write(fileObject.getBinData());
}
} catch (IOException e) {
throw new ApplicationRuntimeException(e);
}
大多數時候,我沒有得到低於錯誤。但有一次,我得到錯誤
29 Nov 2010 10:50:41,925 WARN [http-2020-2] - Unable to present exception page: getOutputStream() has already been called for this response
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:610)
您聲明這與tapestry有關,但是在您的問題中沒有提及任何tapestry。請解釋這是如何掛毯相關或刪除標籤。 – pstanton 2010-11-29 04:04:45
掛毯服務 – cometta 2010-11-29 04:06:46