-
[JSP] 파일 다운로드 구현 - java.lang.IllegalStateException: getOutputStream()Legacy/문제해결 2015. 12. 7. 15:04728x90
파일 다운로드를 구현하다가 다음과 같은 에러가 떴다.
JSP(서블릿 아님.)에서 getOutputStream()를 호출하는 과정에서 에러가 등장했다.
파일이 정상적으로 다운로드 되긴 하는데 콘솔화면에는 다음과 같은 에러메시지가 있었다.
12월 07, 2015 2:50:55 오후 org.apache.catalina.core.StandardWrapperValve invoke
심각: Servlet.service() for servlet [jsp] in context with path [/Project_WebService] threw exception [java.lang.IllegalStateException: getOutputStream() has already been called for this response] with root cause
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:578)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:212)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:115)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:108)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:184)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:120)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
at org.apache.jsp.Tool_005fDownload_jsp._jspService(Tool_005fDownload_jsp.java:230)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.filters.CorsFilter.handleNonCORS(CorsFilter.java:436)
at org.apache.catalina.filters.CorsFilter.doFilter(CorsFilter.java:177)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
우선 에러가 뜬 것부터 좋지 않은데 심각이라고 하니 조금 무서웠다.
구글링을 해보니 JSP를 Servlet으로 변환하는 과정에서 생기는 OutputStream인 JspWriter 때문인데 getOutputStream()을 호출하기 전에 JSP 자체의 OutputStream을 제거할 필요가 있다고 한다. 때문에 getOutputStream()을 호출하기 전에 다음과 같은 코드를 삽입하였다.
out.clear();
out=pageContext.pushBody();
'Legacy > 문제해결' 카테고리의 다른 글
[Node.js] mysql query error (0) 2017.01.15 [Spring] Current request is not of type [org.springframework.web.multipart.MultipartHttpServletRequest]: (0) 2016.11.06 마우스 상하좌우가 반대로 움직임. (3) 2016.07.06 ERROR 1054 (42S22): Unknown column 'password' in 'field list' (1) 2016.05.07 java.lang.NoClassDefFoundError: javax/servlet/ServletRequest 에러 해결 (0) 2016.01.24 [Windows] 올바른 응용프로그램이 아닙니다. (0) 2015.12.07 [Spring Security]<sec:authorize access="isAnonymous()"> 적용시 HTTP 500 에러가 뜨는 경우 (1) 2015.11.19 [VM] Not enough physical memory ... 에러 해결법 (1) 2015.09.03 [Web] 웹 페이지 한글 깨짐 (1) 2015.08.27 [VM Ware] 은행 보안 프로그램이 VMware를 알아채지 못하게 하는 방법 (0) 2015.05.07