JSP中出现getOutputStream() has already been called for this response异常

刚刚研究项目的时候,遇到这个错误。搜了很多资料并自己研究了好久终于算是基本解决了这个问题,在这里记录一下。

出现错误的原因,说出来很简单:

 一般都是在JSP中调用了:response.getOutputStream();来获取输出流。
 并且有意或者无意的使用了out对象来输出内容。

异常的显式原因(自身代码原因):

1、我们都知道,JSP最终会被翻译为一个Java类(Servlet),然后在页面中的所有HTML内容,都是在这个Servlet中的_jspService()方法里面被输出的。

输出的方式是out.write(“**“);

2、又因为JSP页面中你所有写的不加”<%%>”这两个括号的内容都会被自动翻译为out.write(“**“);

不加"<%%>"是包括"<%%>"、"<%@%>"、"<%!%>"的内容。

以及你无意中会写的回车+换行。

3、问题出现了:如果你调用了response.getOutputStream()来获取输出流,又无意中out输出了(“\r\n”)(当然,你自己显示调用out更不行了)就会出现错误。

错误就是getOutputStream() has already been called for this response。

异常的真实原因(java设计使然):

jsp中的out对象,在jsp中是通过这句代码获得的:pageContext.getOut();

1、经过我研究发现:如果你并没有在JSP中写需要write的内容(write方法没有被掉用过),似乎out对象根本就没有被创建。

2、一旦JSP中使用了out.write(),那么pageContext.getOut()就真正的返回了一个JspWriter对象。

3、这样就不知道在哪最终调用了ServletResponse.getWriter();

4、又因为你之前调用了response.getOutputStream();

5、这样最终触发了3和4方法中相同的异常。

    getWriter():IllegalStateException - if the getOutputStream method has already been called for this response object

    getOutputStream():IllegalStateException - if the getOutputStream method has already been called for this response object

    这两个方法是不能共存的,在他们的方法定义中也有描述:

    Either this method or getOutputStream() may be called to write the body, not both.
   Either this method or getWriter() may be called to write the body, not both.

解决方法:

1、无意中使用了out对象的情况:

仔细查找页面中的代码,删除%><%之间的所有内容包括空格和换行符。不能出现所有非Java代码的内容。

2、确实需要使用out对象也要使用getOutputStream的情况:

在JSP页面Java代码块的最后加上:out.clear();

展开阅读全文

【急】 getOutputStream() has already been called for this response

09-26

java.lang.IllegalStateException: getOutputStream() has already been called for this responsern at org.apache.catalina.connector.Response.getWriter(Response.java:611)rn at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)rn at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)rn at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)rn at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:276)rn at java.io.PrintWriter.write(PrintWriter.java:354)rn at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:119)rn at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:326)rn at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:342)rn at com.opensymphony.module.sitemesh.parser.TokenizedHTMLPage.writeBody(TokenizedHTMLPage.java:35)rn at com.opensymphony.module.sitemesh.taglib.decorator.BodyTag.doEndTag(BodyTag.java:26)rn at org.apache.jsp.themes.faces.nh_005fface.decorators.DecoratorMain_jsp._jspx_meth_decorator_005fbody_005f0(DecoratorMain_jsp.java:535)rn at org.apache.jsp.themes.faces.nh_005fface.decorators.DecoratorMain_jsp._jspService(DecoratorMain_jsp.java:315)rn at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)rn at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)rn at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)rn at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)rn at org.apache.jsp.decorators.DecoratorMain_jsp._jspService(DecoratorMain_jsp.java:53)rn at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)rn at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)rn at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)rn at com.opensymphony.module.sitemesh.filter.PageFilter.writeDecorator(PageFilter.java:173)rn at com.opensymphony.module.sitemesh.filter.PageFilter.applyDecorator(PageFilter.java:158)rn at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:62)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at com.smartdot.galaxy.portal.filter.auth.URLProtectionFilter.doFilter(Unknown Source)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at com.smartdot.galaxy.portal.filter.auth.AuthFilter.doFilter(Unknown Source)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at com.smartdot.galaxy.portal.filter.ShareLdapConnectionFilter.doFilter(Unknown Source)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)rn at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at com.smartdot.util.server.SetCharacterEncodingFilter.doFilter(Unknown Source)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)rn at java.lang.Thread.run(Thread.java:595)rn2011-9-26 18:18:23 org.apache.catalina.core.ApplicationDispatcher invokern严重: Servlet.service() for servlet jsp threw exception 论坛

getOutputStream() has already been called for this response

10-28

在action中执行文件写出,功能是实现文件下载。rn但是response.getOoutputStream()是就出现了以下错误。rnjava.lang.IllegalStateException: getOutputStream() has already been called for this responsernat org.apache.catalina.connector.Response.getWriter(Response.java:604)rn at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)rn at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)rn at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)rn at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)rn at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:178)rn at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:118)rn at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:77)rn at org.apache.jsp.main_jsp._jspService(main_jsp.java:277)rn at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)rn at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:557)rn at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:481)rn at org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:156)rn at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)rn at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:362)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)rn at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)rn at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)rn at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)rn at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)rn at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Thread.java:619)rnrn在网上看了很多帖,都是在jsp中进行处理的,不是在action中的代码。rn在jsp中很多人都说是用:out.clear(); 和 out = pageContext.pushBody();就不会出现该错误,我没有试,我用的是action。rn所以在这里请教各位大虾,我在action中应该怎么处理啊,帮帮忙啊。 论坛

getOutputStream() has already been called for this response 问题

11-25

做一个jsp下载excel的功能,功能描述如下:首先将excel下载到服务器,然后从服务器下载到本地。rn最开始是一个页面,点击下载,用ajax跳转到后台,将文件下载到服务器,然后跳回jsp,执行如下js:rnif(xmlHttpRequest.status==200)//服务器状态码rn var loadDir = "/webrpt/loadFile.jsp?flag=1&dir=BBSJ_DOWNLOAD.zip" ;rn window.location.href (loadDir) ;rnrn此时跳转到下载jsp页面,自动弹出下载窗口,下载jsp loadFile.JSP代码如下:rn[code="java"]rn<%@ page contentType="text/html;charset=GBK" %>rn <%@ page import="java.io.*" %>rn rn rn rn <%rn java.io.BufferedInputStream bis=null;rn java.io.BufferedOutputStream bos=null;rn tryrn String filename=request.getParameter("dir");rn response.reset();rn File fileLoad=new File("D://",request.getParameter("dir"));rn filename=new String(filename.getBytes("iso8859-1"),"gbk");rn response.setContentType("application/x-download");rn response.setHeader("Content-disposition","attachment; filename="+new String(filename.getBytes("gbk"),"iso8859-1"));rn bis=new java.io.BufferedInputStream(new java.io.FileInputStream(fileLoad));rn bos=new java.io.BufferedOutputStream(response.getOutputStream());rn byte[] buff = new byte[2048];rn int bytesRead;rn while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))rn bos.write(buff,0,bytesRead);rn rn bos.flush();rn catch(Exception e)rn e.printStackTrace();rn finallyrn if(bis != null)bis.close();rn if(bos != null)bos.close();rn %>rn rn rn[/code]rn加断点显示,当弹出下载窗口的时候还没报错,再执行之后的outputstream出错,错误信息如下:rn严重: Servlet.service() for servlet debugjsp threw exceptionrnjava.lang.IllegalStateException: getOutputStream() has already been called for this responsern at org.apache.catalina.connector.Response.getWriter(Response.java:596)rn at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:186)rn at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:124)rn at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:117)rn at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:191)rn at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)rn at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)rn at org.apache.jsp.loadFile_jsp._jspService(org.apache.jsp.loadFile_jsp:84)rn at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)rn at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)rn at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)rn at java.lang.Thread.run(Thread.java:595)rnrn整了一天了,一直没有解决。。。。 问答

关于:getOutputStream() has already been called for this response

03-13

最近开发了一个网页,要求从数据库中下载图片!rn程序代码为rn<%byte[] blocco = rsNewsTP.getBytes("ZP");response.setContentType("image/jpeg");ServletOutputStream op = response.getOutputStream();op.write(blocco[0]);%>rn但是运行进提示:rntype Exception reportrnrnmessage rnrndescription The server encountered an internal error () that prevented it from fulfilling this request.rnrnexception rnrnjava.lang.IllegalStateException: getOutputStream() has already been called for this responsern org.apache.coyote.tomcat5.CoyoteResponse.getWriter(CoyoteResponse.java:599)rn org.apache.coyote.tomcat5.CoyoteResponseFacade.getWriter(CoyoteResponseFacade.java:163)rn org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:122)rn org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:115)rn org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:324)rn org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:335)rn org.apache.jsp.TMPhbt2metzq2_jsp._jspService(TMPhbt2metzq2_jsp.java:388)rn org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rnrnrnnote The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.rnrn搞不明白为什么,网络上找过,他们说,<%%>中间不能有空格!但是我己经删除了!!rn还是这样!!!rn 论坛

错误信息:getOutputStream() has already been called for this response

11-22

在写下载(把数据保存在txt中打开)时出现的提示。麻烦大家帮忙想招啦,应该是遇到response.getOutputStream()这句的时候报的错,但我是清空再做的操作啊,我自己实在是找不到解决办法。我的代码如下:rnrnrnif (type.equals("link4_one_loaddown")) rn File f = null;rn FileInputStream fileinputstream = null;rn String downloadfilepath = "/WEB-INF/download/";rn String filename = "testDownload.txt";rn String path= request.getRealPath("/");rn String filepathname = path + downloadfilepath;rnrnrn //写入文件完成rn EmployeeBean empbean = new EmployeeBean(ds);rn EmployeeVO emp = empbean.getEmployee(request.getParameter("id"));rn //读出文件开始rn try rn f = new File(filepathname, filename);rn f.createNewFile();//创建文件rn LoadDownBean loadbean=new LoadDownBean();rn loadbean.writeFile(emp,f); //写文件的具体过程rnrnrn fileinputstream = new FileInputStream(rn filepathname+ filename);rnrn servletoutputstream = response.getOutputStream();rn response.reset();rn response.setHeader("Content-disposition",rn "attachment; filename=" + filename);rn response.setContentType("text/plain;charset=gb2312");rn int j = 0;rn int k = 0;rn byte abyte0[] = new byte[1024];rn while ((k = fileinputstream.read(abyte0)) != -1) rn j += k;rn servletoutputstream.write(abyte0);rn rnrn catch (Exception ex) rn ex.printStackTrace();rn finally rn try rn servletoutputstream.close();rn fileinputstream.close();rn File f1 = new File(filepathname+filename);rn if (f1.exists()) rn System.out.println("linnan");rn f1.delete(); //删除File.txt文件rn rn catch (Exception ex1) rn ex1.printStackTrace();rn rn rnrn报错信息如下:rnERROR - Servlet.service() for servlet action threw exceptionrnjava.lang.IllegalStateException: getOutputStream() has already been called for this responsern at org.apache.catalina.connector.Response.getWriter(Response.java:596)rn at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:186)rn at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:156)rn…… 论坛

Servlet抛getOutputStream() has already been called for this response异常

11-02

[code=Java]rnError captured: java.lang.IllegalStateException: Cannot forward after response has been committedrnjava.lang.IllegalStateException: Cannot forward after response has been committedrn at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:313)rn at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)rn at org.openbravo.base.HttpBaseServlet.serviceInitialized(HttpBaseServlet.java:134)rn at org.openbravo.base.secureApp.HttpSecureAppServlet.service(HttpSecureAppServlet.java:257)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)rn at org.openbravo.utils.SessionExpirationFilter.doFilter(SessionExpirationFilter.java:54)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)rn at org.openbravo.utils.CharsetFilter.doFilter(CharsetFilter.java:27)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)rn at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)rn at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)rn at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)rn at java.lang.Thread.run(Thread.java:619)rn306625 [http-8080-Processor23] ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].Servlet.service() for servlet X3300064 threw exceptionrnjava.lang.IllegalStateException: getOutputStream() has already been called for this responsern at org.apache.catalina.connector.Response.getWriter(Response.java:607)rn at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:196)rn at org.openbravo.base.secureApp.HttpSecureAppServlet.bdErrorGeneral(HttpSecureAppServlet.java:462)rn at org.openbravo.base.secureApp.HttpSecureAppServlet.service(HttpSecureAppServlet.java:275)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)rn at org.openbravo.utils.SessionExpirationFilter.doFilter(SessionExpirationFilter.java:54)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)rn at org.openbravo.utils.CharsetFilter.doFilter(CharsetFilter.java:27)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)rn at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)rn at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)rn at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)rn at java.lang.Thread.run(Thread.java:619)rnrn[/code]rn求解决方法,谢谢!rnPS:rn我是想在文件下载以后重定向页面,结果就报上面的错。rn[code=Java]rn// 有下载文件rn printPagePdf(response, vars, strCRId);rn // 刷新页面rn //response.sendRedirect(strDireccion + request.getServletPath());rn request.getRequestDispatcher(request.getServletPath()).forward(request,response);rn[/code]rn刷新页面用两种方法都不行。rn 论坛

filter 过滤出现 getOutputStream() has already been called for this response

04-16

number.jsprn[code=Java]rn<%@ page language="java" contentType="text/html; charset=UTF-8"rn pageEncoding="UTF-8"%>rn <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>rnrnrnrn rn rn Insert title herernrnrn set rn rn rn session$session rn context$applicationScope.applicationrn rnrn[/code]rnrnweb.xmlrn[code=XML]rn changeFilterrn my.ChangeFilterrnrn rn changeFilterrn *rn rn [/code]rnrnrnrnChangeFilter.javarnrnrn[code=Java]package my;rnrnimport java.io.IOException;rnimport java.io.PrintWriter;rnrnimport javax.servlet.*;rnimport javax.servlet.http.*;rnrnpublic class ChangeFilter implements Filterrn ResponseWrapper response;rn String goal;rn @Overridern public void destroy() rn // TODO Auto-generated method stubrn rn rnrn @Overridern public void doFilter(ServletRequest arg0, ServletResponse arg1,rn FilterChain arg2) throws IOException, ServletException rn // TODO Auto-generated method stubrn response=new ResponseWrapper((HttpServletResponse )arg1);rn arg2.doFilter(arg0, response );rn change(arg0);rn PrintWriter out=arg1.getWriter();rn out.write(goal);rn out.close();rn rn rnrn @Overridern public void init(FilterConfig arg0) throws ServletException rn // TODO Auto-generated method stubrn rn rn private void change(ServletRequest arg0)rn goal=(String)arg0.getServletContext().getInitParameter("newName"); rn if(goal!=null)rn goal=response.toString().replaceAll("google", goal);rn elsern goal=response.toString();rn rn rnrn[/code]rnrnrn运行后 出现rnrnjava.lang.IllegalStateException: getOutputStream() has already been called for this responsern at org.apache.catalina.connector.Response.getWriter(Response.java:636)rn at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:205)rn at my.ChangeFilter.doFilter(ChangeFilter.java:24)rnrnrn而且没有将那个网页的 google替换掉rnrn我怀疑是 rnrn没有经过过滤 rnrn该如何修改是好[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/monkey/2.gif][/img] 论坛

错误信息:java.lang.IllegalStateException: getOutputStream() has already been called

12-20

java.lang.IllegalStateException: getOutputStream() has already been called for this responsern at org.apache.catalina.connector.Response.getWriter(Response.java:607)rn at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:196)rn at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)rn at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)rn at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)rn at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:171)rn at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:116)rn at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:76)rn at org.apache.jsp.jspx.temp_jsp._jspService(temp_jsp.java:75)rn at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)rn at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:691)rn at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:594)rn at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:505)rn at org.apache.struts.chain.commands.servlet.PerformForward.handleAsInclude(PerformForward.java:127)rn at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:78)rn at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:51)rn at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:48)rn at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)rn at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)rn at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)rn at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:280)rn at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1858)rn at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:459)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)rn at com.mdao.emap.webapp.filter.WebFilter.doFilter(WebFilter.java:38)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)rn at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)rn at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)rn at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)rn at java.lang.Thread.run(Thread.java:595)rn 论坛

java.lang.IllegalStateException: getOutputStream() has already been called for

02-13

[code=java]rn09-Feb-2015 10:09:27.784 SEVERE [http-apr-80-exec-18] org.apache.catalina.core.ApplicationDispatcher.invoke Servlet.service() for servlet jsp threw exceptionrn java.lang.IllegalStateException: getOutputStream() has already been called for this responsern at org.apache.catalina.connector.Response.getWriter(Response.java:578)rn at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:212)rn at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109)rn at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109)rn at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109)rn at org.springframework.security.web.context.SaveContextOnUpdateOrErrorResponseWrapper.getWriter(SaveContextOnUpdateOrErrorResponseWrapper.java:109)rn at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:115)rn at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:108)rn at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:175)rn at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:120)rn at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)rn at org.apache.jsp.WEB_002dINF.views.fail_jsp._jspService(fail_jsp.java:122)rn at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:431)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721)rn at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)rn at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:523)rn at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:229)rn at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)rn at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)rn at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)rn at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)rn at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)rn at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn[/code]rnrnrnrnrn经过跟踪程序,发现JSP中用这段报的原因 rn<%@ page import="org.apache.commons.codec.binary.Base64"%> rn<%for(int i=0;i rn rnrn<%%> rn中的src="<%=path %>/back/fbsp/viewPic/<%=picPath %>“。这段是输出图片用的,页面上加载10几个图,每个图在200k左右,是在页面没全部加载完时,又刷新页面造成的,不知道如何解决 论坛

org.apache.jasper.JasperException: getOutputStream() has already been called for

05-10

rn出错了!!看不出来问题在哪?rnrn严重: Servlet.service() for servlet jsp threw exceptionrnorg.apache.jasper.JasperException: getOutputStream() has already been called for this responsern at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)rn at java.lang.Thread.run(Unknown Source)rn 论坛

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

03-01

我用此类下载文件,下载正常但在日志中报如下错误,请高手指教。rnrnpublic void downloadFile(String s, String s1, String s2, int i)rn throws SmartUploadException, IOException, ServletExceptionrn rn if(s == null)rn throw new IllegalArgumentException(String.valueOf((new StringBuffer("File '")).append(s).append("' not found (1040).")));rn if(s.equals(""))rn throw new IllegalArgumentException(String.valueOf((new StringBuffer("File '")).append(s).append("' not found (1040).")));rn if(!isVirtual(s) && m_denyPhysicalPath)rn throw new SecurityException("Physical path is denied (1035).");rn if(isVirtual(s))rn s = m_application.getRealPath(s);rn java.io.File file = new java.io.File(s);rn java.io.FileInputStream fileinputstream = new java.io.FileInputStream(file);rn long l = file.length();rn boolean flag = false;rn int j = 0;rn byte abyte0[] = new byte[i];rn if(s1 == null)rn m_response.setContentType("application/x-msdownload");rn elsern if(s1.length() == 0)rn m_response.setContentType("application/x-msdownload");rn elsern m_response.setContentType(s1);rn m_response.setContentLength((int)l);rn m_contentDisposition = m_contentDisposition == null ? "attachment;" : m_contentDisposition;rn if(s2 == null)rn m_response.setHeader("Content-Disposition", String.valueOf((new StringBuffer(String.valueOf(m_contentDisposition))).append(" filename=").append(toUtf8String(getFileName(s)))));rn //m_response.setHeader("Content-Disposition", (new StringBuilder()).append(m_contentDisposition).append(" filename=").append(toUtf8String(getFileName(s))).toString());rn elsern if(s2.length() == 0)rn m_response.setHeader("Content-Disposition", m_contentDisposition);rn elsern m_response.setHeader("Content-Disposition", String.valueOf((new StringBuffer(String.valueOf(m_contentDisposition))).append(" filename=").append(toUtf8String(s2))));rn //m_response.setHeader("Content-Disposition", (new StringBuilder()).append(m_contentDisposition).append(" filename=").append(toUtf8String(s2)).toString());rnrn m_response.flushBuffer();rn rn dorn rn if((long)j >= l)rn break;rn int k = fileinputstream.read(abyte0, 0, i);rn j += k;rn m_response.getOutputStream().write(abyte0, 0, k);rn if(getSize() <= 0x10000)rn m_response.flushBuffer();rn while(true);rn fileinputstream.close();rn 论坛

关于getOutputStream() has already been called for this response的问题

12-31

新近开发的OA系统,使用tomcat作为servlet容器。在tomcat的web.xml配置文件中将invoker给打开rn了。rn本OA系统运行的硬件环境是 sun 480,操作系统是solaris 9。rntomcat中关于 内存和线程数的设置是如下:rnJAVA_OPTS="-XX:MaxPermSize=256m -Xms1024m -Xmx1024m";export JAVA_OPTSrnrn rnrnrnrn运行系统经常出现如下错误:rn2005-12-30 19:18:30 StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exceptionrnjava.lang.IllegalStateException: getOutputStream() has already been called for this responsern at org.apache.coyote.tomcat5.CoyoteResponse.getWriter(CoyoteResponse.java:600)rn at org.apache.coyote.tomcat5.CoyoteResponseFacade.getWriter(CoyoteResponseFacade.java:164)rn at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:124)rn at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:117)rn at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:191)rn at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)rn at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)rn at org.apache.jsp.doc.receiveOpenDoc_jsp._jspService(receiveOpenDoc_jsp.java:131)rn at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(rnrn紧接着就出现线程不组的错误,如下:rn2005-12-30 22:23:34 ApplicationDispatcher[/zsjgj] Servlet.service() for servlet jsp threw exceptionrnjava.lang.OutOfMemoryError: unable to create new native threadrn at java.lang.Thread.start0(Native Method)rn at java.lang.Thread.start(Thread.java:574)rn at java.lang.ref.Finalizer$1.run(Finalizer.java:113)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.lang.ref.Finalizer.forkSecondaryFinalizer(Finalizer.java:121)rn at java.lang.ref.Finalizer.runFinalization(Finalizer.java:126)rn at java.lang.Runtime.runFinalization0(Native Method)rn rnrn请求帮助!!!rnrnrn 论坛

getOutputStream() has already been called for this response,大家来找茬

06-17

[color=#FF0000]眼睛比较好使的同志找一下,后台的PrintWriter out = response.getWriter()和哪冲突了[/color]rn下面是简单的登录页面rn[code=HTML]rnrnrnrn rn rn rn #resource.Login_Titlern rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn #resource.Login_Lable_UserName:rn rn rn rn #resource.Login_Lable_PassWord:rn rn rn rn rn #resource.Login_Lable_ValidCode:rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn[/code]rn下面是简单的js代码rn[code=JScript]$(function()rn faceLogoFunction.findFaceLogo(function(date)rn $("#logo").attr("src",date.faceLogo);rn $("#logo").css("width","248px");rn $("#logo").css("height","72px");rn $("#copyright").html(date.faceCopyright);rn );rn);rnfunction onEnter()rn $("#btnEnter").attr("disabled","false");rn var strvalid = $.trim($("#txtVaildCode").val());rn var strun = $.trim($("#username").val());rn var strpw = $.trim($("#password").val());rn $("#vaildCode").click(function()rn this.src='servlet/WebAppInterface?Action=getCheckCode&&'+new Date();rn );rn if(strun==null || strun=="")rn alert('请输入用户名!');$("#username").select();$("#btnEnter").attr("disabled","");return false;rn rn if(strpw==null || strpw=="")rn alert('请输入密码!');$("#password").select();$("#btnEnter").attr("disabled","");return false;rn rn if(strvalid==null || strvalid=="")rn alert('请输入验证码!');$("#txtVaildCode").select();$("#btnEnter").attr("disabled","");return false;rn rn rn $.ajax(rn url: "servlet/WebAppInterface?Action=Verify",rn success: function(strval)rn if(strval==$("#txtVaildCode").val())rn $.ajax(//提交登录rn type: "post",rn data: "username="+strun+"&password="+strpw+"&Lang="+$("#drpLang").val()+"",rn url: "servlet/SSOAuth?PWSecurity=false",rn success: function(msg)rn if(msg!='false')rn window.location.href = "servlet/Loader?tokenid="+msg;rn //window.open('servlet/Loader?tokenid='+msg,'','left=0,top=0,width='+(screen.availWidth-10)+',height='+(screen.availHeight-30)+'fullscreen=1,toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,status=no;');rn //window.opener = null;rn //window.open('',"_self");rn //window.close();rn elsern alert('用户名或密码不对');$("#btnEnter").attr("disabled","");return false;rn rn rn );rn elsern alert('验证码不对!');$("#btnEnter").attr("disabled","");return false;rn rn rn );rnrnrnfunction keyDown(e)rn if(!e)var e=window.event; rn var kc=e.which||e.keyCode; rn switch(kc) rn case 13:onEnter();break; rn rn rn rndocument.onkeydown = keyDown;rn$(function());[/code]rn下面是后台的方法rn[code=Java]public void doGet(HttpServletRequest request, HttpServletResponse response)rn throws ServletException, IOException rn response.setHeader("Pragma", "No-cache");rn response.setHeader("Cache-Control", "no-cache");rn response.setDateHeader("Expires", 0);rnrn String strResutl = "";rn String action = request.getParameter("Action");rn HttpSession session = request.getSession();rn if (action != "" && action != null) rn rn if (action.equals("Verify")) // 验证码rn strResutl = session.getAttribute("CheckCode").toString();rn else if (action.equals("ValidUser")) // 用户登录rn strResutl = ValidUser(request, response);rn else if (action.equals("Logout")) // 退出登录rn Logout(request, response);rn else if (action.equals("ReadModels")) // 左边树菜单rn strResutl = ReadModels(request, response);rn else if (action.equals("getCheckCode")) // 左边树菜单rn getCheckCode(request, response);rn rn rn response.setContentType("text/html;charset=GB2312");rn PrintWriter out = response.getWriter();rn out.print(strResutl);rn //System.out.println(strResutl);rn out.flush();rn out.close();rn rn [/code] 论坛

poi输出word报错,getOutputStream() has already been called for this response

05-17

做项目的时候用poi向word模板写入数据,在前段用创建iframe的方式进行下载,结果下载的时候报错了。rn错误信息如下:rn[code=java]rnorg.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Fail to save: an error occurs while saving the package : The part /docProps/core.xml fail to be saved in the stream with marshaller org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller@d5b0700rn at org.apache.poi.openxml4j.opc.ZipPackage.saveImpl(ZipPackage.java:502)rn at org.apache.poi.openxml4j.opc.OPCPackage.save(OPCPackage.java:1467)rn at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:217)rn at com.hhwy.bjyps.meeting.controller.MeetingController.generateMeetingDoc(MeetingController.java:205)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:498)rn at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)rn at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)rn at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)rn at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)rn at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)rn at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)rn at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)rn at com.hhwy.framework.mvc.DispatchServlet.doDispatch(DispatchServlet.java:931)rn at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)rn at com.hhwy.framework.mvc.DispatchServlet.doService(DispatchServlet.java:386)rn at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)rn at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)rn at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)rn at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)rn at com.hhwy.sso.client.filter.SessionFilter.doFilter(SessionFilter.java:129)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)rn at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)rn at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)rn at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:495)rn at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)rn at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:767)rn at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1347)rn at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)rn at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)rn at java.lang.Thread.run(Thread.java:745)rnrnjava.lang.IllegalStateException: getOutputStream() has already been called for this responsern at org.apache.catalina.connector.Response.getWriter(Response.java:603)rn at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:211)rn at com.hhwy.framework.mvc.GlobalMethodHandlerExeptionResolver.resolveException(GlobalMethodHandlerExeptionResolver.java:82)rn at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1167)rn at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1004)rn at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)rn at com.hhwy.framework.mvc.DispatchServlet.doDispatch(DispatchServlet.java:931)rn at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)rn at com.hhwy.framework.mvc.DispatchServlet.doService(DispatchServlet.java:386)rn at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)rn at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)rn at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)rn at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)rn at com.hhwy.sso.client.filter.SessionFilter.doFilter(SessionFilter.java:129)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)rn at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)rn at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)rn at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:495)rn at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)rn at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:767)rn at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1347)rn at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)rn at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)rn at java.lang.Thread.run(Thread.java:745)rn[/code]rn代码在楼下: 论坛

有关getOutputStream() has already been called for this response,敬请留步!

06-23

功能:根据byte[],输出图片到JSP页面rn开发:servlet + jsprnservlet代码:rn/**rn * showPicrn * 测试使用,显示图片rn * @param request HttpServletRequestrn * @param response HttpServletResponsern */rn private void showPic(HttpServletRequest request, HttpServletResponse response)rn rn request.setAttribute("leftPic",Common.busiLeftPic(request,response));//送入一个byte[]rn request.setAttribute("centerPic",Common.busiCenterPic(request,response));//送入一个byte[]rn request.setAttribute("rightPic",Common.busiRightPic(request,response));//送入一个byte[]rnrn dispatch(request,response,JspName.picTest,getServletContext());rnrn /**rn * 资源分发rn * @param request HttpServletRequestrn * @param response HttpServletResponsern * @param Location Stringrn */rn public static void dispatch(HttpServletRequest request, HttpServletResponse response, String Location,ServletContext context)rn rn RequestDispatcher dipatcher = null;rn tryrn rn dipatcher = context.getRequestDispatcher(Location);rn //dipatcher = request.getRequestDispatcher(Location);rn dipatcher.forward(request,response);rn rn catch(Exception e)rn rn System.out.println("dispatch Err: " + e.getMessage());rn rn dipatcher = null;rn rnrnJSP页面rnrn<%@ page language="java" import="java.sql.*" errorPage="" %>rn<%@ page import= "java.lang.*"%>rn<%@ page import= "java.sql.*"%>rn<%@ page import= "java.util.*"%>rn<%rnresponse.setContentType("image/jpeg");rnbyte[] leftPic = null;rnif( request.getAttribute("leftPic") != null )rn leftPic = (byte[])request.getAttribute("leftPic");rn rn ServletOutputStream leftSos = response.getOutputStream();rnleftSos.write(leftPic,0,leftPic.length);rnleftSos.flush();rnleftSos.close();rn %>rnrn错误类型:rnrnApplicationDispatcher[]: Servlet.service() for servlet debugjsp threw exceptionrnrnorg.apache.jasper.JasperException: getOutputStream() has already been called for this responsernrn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)rnrn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)rnrn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)rnrn at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)rnrn at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)rnrn at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)rnrn at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)rnrn at com.freely.busi.Common.dispatch(Common.java:36)rnrn at com.freely.busi.OperatorMgr.showPic(OperatorMgr.java:71)rnrn at com.freely.busi.OperatorMgr.doGet(OperatorMgr.java:55)rnrn at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)rnrn at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)rnrn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)rnrn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)rnrn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)rnrn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rnrn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rnrn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rnrn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rnrn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rnrn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rnrn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rnrn at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)rnrn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)rnrn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rnrn at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)rnrn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)rnrn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)rnrn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)rnrn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rnrn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rnrn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)rnrn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rnrn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rnrn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rnrn at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)rnrn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)rnrn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)rnrn at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)rnrn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)rnrn at java.lang.Thread.run(Thread.java:534)rnrndispatch Err: getOutputStream() has already been called for this responsernrn 论坛

没有更多推荐了,返回首页