getWriter() has already been called for this response

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cuiyaoqiang/article/details/68065539

问题描述:
servlet中先调用PrintWriter out = response.getWriter();我使用jfreechart的时候需要用到ServletOutputStream outputStream = response.getOutputStream();此时报错如下:

getWriter() has already been called for this response

意思是response已经被其他对象调用了,导致无法继续使用如下类似的方法:

out.print();
out.flush();
out.close();

解决方案:

response.reset();//重点
response.setHeader("Cache-Control", "no-cache");
response.setContentType("image/png");
ServletOutputStream outputStream = response.getOutputStream();
展开阅读全文

[BlazeDS]getWriter() has already been called for this response

05-19

SSH整合flex4.6出现的问题:rn1、没有整合flex之前,ssh是能够正常运行的。rn2、flex没有整合ssh,只整合java的时候,也是可能正常运行的。rn3、整合flex到ssh的时候,配置与之前整合java的配置一样:rn在web.xml中增加如下代码:rn[code=java]rnBlazeDSrn BlazeDS Applicationrn rn MessageBrokerServletrn MessageBrokerServletrn flex.messaging.MessageBrokerServletrn rn services.configuration.filern /WEB-INF/flex/services-config.xmlrn rn 1rn rn rn MessageBrokerServletrn /messagebroker/*rn rn[/code]rn在remoting-config.xml中配置如下:rn[code=java]rn rn rn rn rn rn com.text.SSHFlexrn rn [/code]rnrn启动tomcat,然后输入:rnhttp://127.0.0.1/Test/messagebroker/amfrn没的报错(据说不报错说明整合成功)。rn新建flex项目,在连接服务端的时候,验证通过。rn以下是mxml的部分内容:rn[code=java]rnprotected function application1_creationCompleteHandler():voidrn rn text_flex.sayHello("helloWorld"); rn rnrn rn rn [/code]rn我在sayHello这个方法中加了断点,调试运行的时候,根本没有进去就报错了:rn[BlazeDS]getWriter() has already been called for this responsernjava.lang.IllegalStateException: getWriter() has already been called for this responsernrn我是刚学的flex,是不是整合的时候,哪里不正确啊!rn请各位高手赐教!rn忠心祝愿各位工作愉快!rn谢谢! 论坛

【急】 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 问题

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-29

错误信息rn严重: Servlet.service() for servlet jsp threw exceptionrnjava.lang.IllegalStateException: getOutputStream() has already been called for this responsern at org.apache.catalina.connector.Response.getWriter(Response.java:610)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:180)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.WEB_002dINF.pages.successMessage_jsp._jspService(successMessage_jsp.java:69)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:374)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: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.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:361)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265)rn at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249)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:236)rn at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)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:236)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:236)rn at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:148)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:93)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:128)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:104)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)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:236)rn at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:148)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:128)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)rn at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468)rn at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at plantix.web.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:84)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at plantix.core.context.ThreadContextCleanerFilter.doFilter(ThreadContextCleanerFilter.java:35)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: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) 论坛

错误信息: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…… 论坛

关于: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 论坛

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