STATUS : Closed
Scenario :
jsp to generate a report and on click of a button download the report xls from the server. Code in the jsp is as follows.
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition",
"attachment; filename=Report.xls");
OutputStream out1 =response.getOutputStream();
WritableWorkbook workbook = Workbook.createWorkbook(out1);
Resolution :
Moved the code in the jsp to a servelet
Possible RootCause :
You cannot get a handle to the multiple output stream objects. When the jsp code gets compiled to plain java it adds code " out.write() " to write the jsp content to the outputstream. Since you already have got a handle to the ouputstream the out.write() system code throws the exception. Hence moving the code to a servelet solves the issue.
Exception
[Exception] [java.lang.IllegalStateException: getOutputStream() has already been called for this response] with root cause
헤르메스의날개
2013. 7. 29. 15:46
728x90
java.lang.IllegalStateException: getOutputStream() has already been called for this response
out.clear();
out=pageContext.pushBody();
요 두줄을 OutputStream하기 전에 넣어주면 되겠다. out은 jsp 웹페이지 자신을 가리키는 것 ! ! !
jsp에서는 servlet으로 변환될때 내부적으로 out 객체가 자동으로 생성되기 때문에 따로 out 객체를 만들면 충돌이 일어나서 저런 메시지가 뜨는 것이라고 한다.
out.clear();
out=pageContext.pushBody();
BufferedInputStream fin = new BufferedInputStream(new FileInputStream(file));
OutputStream outs = response.getOutputStream();
728x90