高分求解:java.lang.IllegalStateException: getOutputStream() has already been called for this response

thwhhelen 2005-03-01 09:41:44
我用此类下载文件,下载正常但在日志中报如下错误,请高手指教。

public void downloadFile(String s, String s1, String s2, int i)
throws SmartUploadException, IOException, ServletException
{
if(s == null)
throw new IllegalArgumentException(String.valueOf((new StringBuffer("File '")).append(s).append("' not found (1040).")));
if(s.equals(""))
throw new IllegalArgumentException(String.valueOf((new StringBuffer("File '")).append(s).append("' not found (1040).")));
if(!isVirtual(s) && m_denyPhysicalPath)
throw new SecurityException("Physical path is denied (1035).");
if(isVirtual(s))
s = m_application.getRealPath(s);
java.io.File file = new java.io.File(s);
java.io.FileInputStream fileinputstream = new java.io.FileInputStream(file);
long l = file.length();
boolean flag = false;
int j = 0;
byte abyte0[] = new byte[i];
if(s1 == null)
m_response.setContentType("application/x-msdownload");
else
if(s1.length() == 0)
m_response.setContentType("application/x-msdownload");
else
m_response.setContentType(s1);
m_response.setContentLength((int)l);
m_contentDisposition = m_contentDisposition == null ? "attachment;" : m_contentDisposition;
if(s2 == null)
m_response.setHeader("Content-Disposition", String.valueOf((new StringBuffer(String.valueOf(m_contentDisposition))).append(" filename=").append(toUtf8String(getFileName(s)))));
//m_response.setHeader("Content-Disposition", (new StringBuilder()).append(m_contentDisposition).append(" filename=").append(toUtf8String(getFileName(s))).toString());
else
if(s2.length() == 0)
m_response.setHeader("Content-Disposition", m_contentDisposition);
else
m_response.setHeader("Content-Disposition", String.valueOf((new StringBuffer(String.valueOf(m_contentDisposition))).append(" filename=").append(toUtf8String(s2))));
//m_response.setHeader("Content-Disposition", (new StringBuilder()).append(m_contentDisposition).append(" filename=").append(toUtf8String(s2)).toString());

m_response.flushBuffer();

do
{
if((long)j >= l)
break;
int k = fileinputstream.read(abyte0, 0, i);
j += k;
m_response.getOutputStream().write(abyte0, 0, k);
if(getSize() <= 0x10000)
m_response.flushBuffer();
} while(true);
fileinputstream.close();
}
...全文
192 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhang21cnboy 2005-03-02
  • 打赏
  • 举报
回复
m_response.getOutputStream().write(abyte0, 0, k);
这个地方,你多次调用了response的getOutputStream()方法!

在循环之前OutputStream out = m_response.getOutputStream();
在循环里面用out.write()
jgo 2005-03-02
  • 打赏
  • 举报
回复
Response流已经被返回了,但你还试图调用它的输出流。
congbailing_914 2005-03-02
  • 打赏
  • 举报
回复

学习!
javagodness 2005-03-02
  • 打赏
  • 举报
回复
我不会,只能帮您顶了。
thwhhelen 2005-03-02
  • 打赏
  • 举报
回复
up
liuchunjp 2005-03-01
  • 打赏
  • 举报
回复
帮你up
xitianjile 2005-03-01
  • 打赏
  • 举报
回复
你是在webpump下面吧.
你把调用这个类的方法放到第一个action里面..
就不会出异常了.
thwhhelen 2005-03-01
  • 打赏
  • 举报
回复
xitianjile(空想社會主義):
你说的我不明白,请再详细些,

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧