本文主要是介绍下载文件时报异常:java.lang.IllegalStateException: getOutputStream() has already been called for this respons,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
jsp下载文件时报错。
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:582)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:227)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:114)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:114)
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:179)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:120)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
at org.apache.jsp.WEB_002dINF.webpage.common.error._500_jsp._jspService(_500_jsp.java:223)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
产生这样的异常原因:是web容器生成的servlet代码中有out.write(""),这个和JSP中调用的response.getOutputStream()产生冲突。即Servlet规范说明,不能既调用
1、如果是jsp里调用的response,可在调用前加上下面代码。
out.clear();
out = pageContext.pushBody();
2、如果只又java中使用到,则action里,最终返回值都设置为null
这篇关于下载文件时报异常:java.lang.IllegalStateException: getOutputStream() has already been called for this respons的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!