您先冲洗response
后再尝试冲洗forward
。容器已经将其发送response
回客户端,现在在如何forward
向另一个JSP发送请求方面陷入了困境,因此它在抛出异常的途中中止了操作。HTTP是一个 模型。一旦你 要求 ,你得到一个 回应 。但是,一旦 响应 已经提交,整个交易就结束了。
outStream.write(outArray);
// you already committed the response here by flushing the output stream
outStream.flush();
//block2
request.setAttribute("Message", str1);
request.setAttribute("MessageDetails", str2);
// this is illegal after you have already flushed the response
request.getRequestDispatcher("/MyFile.jsp").forward(request, response);
根据Javadoc:
IllegalStateException-如果响应已经提交。
不,你不能两者都做。您需要决定想要什么。将字节写入响应设置正确的HEADERS和MIME- TYPE。您无法从相同的响应中获得浏览器下载内容以及显示JSP页面。