问题描述
org.apache.catalina.core.StandardWrapperValveinvoke严重:Servlet.service()forservletjspthrewexceptionjava.lang.IllegalStateException:getOutputStream()hasalreadybeencalledforthisresponseatorg.apache.catalina.connector.Response.getWriter(Response.java:610)atorg.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)atorg.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)atorg.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)atorg.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:188)atorg.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:118)atorg.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:77)atorg.apache.jsp.image_jsp._jspService(image_jsp.java:143)atorg.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717)atorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)atorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)atorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)atorg.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)atorg.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)atjava.lang.Thread.run(UnknownSource)
解决方案
解决方案二:
你的Servlet流程处理代码有问题.
解决方案三:
Servlet最后写出流时出错了。
解决方案四:
Servlet最后写出流时出错了。
解决方案五:
servlet代码多错误处理的逻辑有问题
解决方案六:
java.lang.IllegalStateException:getOutputStream()hasalreadybeencalledforthisresponse
解决方案七:
没有关闭输出流
解决方案八:
生成有4个随机数字和杂乱背景的图片,数字和背景颜色会改变,服务器端刷新(用history.go(-1)也会变)原型参考ALIBABA------------产生验证码图片的文件-----image.jsp-------------------------------------------<%@pagecontentType="image/jpeg"import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*"%><%!ColorgetRandColor(intfc,intbc){//给定范围获得随机颜色Randomrandom=newRandom();if(fc>255)fc=255;if(bc>255)bc=255;intr=fc+random.nextInt(bc-fc);intg=fc+random.nextInt(bc-fc);intb=fc+random.nextInt(bc-fc);returnnewColor(r,g,b);}%><%//设置页面不缓存response.setHeader("Pragma","No-cache");response.setHeader("Cache-Control","no-cache");response.setDateHeader("Expires",0);//在内存中创建图象intwidth=60,height=20;BufferedImageimage=newBufferedImage(width,height,BufferedImage.TYPE_INT_RGB);//获取图形上下文Graphicsg=image.getGraphics();//生成随机类Randomrandom=newRandom();//设定背景色g.setColor(getRandColor(200,250));g.fillRect(0,0,width,height);//设定字体g.setFont(newFont("TimesNewRoman",Font.PLAIN,18));//画边框//g.setColor(newColor());//g.drawRect(0,0,width-1,height-1);//随机产生155条干扰线,使图象中的认证码不易被其它程序探测到g.setColor(getRandColor(160,200));for(inti=0;i<155;i++){intx=random.nextInt(width);inty=random.nextInt(height);intxl=random.nextInt(12);intyl=random.nextInt(12);g.drawLine(x,y,x+xl,y+yl);}//取随机产生的认证码(4位数字)StringsRand="";for(inti=0;i<4;i++){Stringrand=String.valueOf(random.nextInt(10));sRand+=rand;//将认证码显示到图象中g.setColor(newColor(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));//调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成g.drawString(rand,13*i+6,16);}//将认证码存入SESSIONsession.setAttribute("rand",sRand);//图象生效g.dispose();//输出图象到页面ImageIO.write(image,"JPEG",response.getOutputStream());%>---------------使用验证码图片的文件---------a.jsp------------------------------------<%@pagecontentType="text/html;charset=gb2312"%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><title>认证码输入页面</title><metahttp-equiv="Content-Type"content="text/html;charset=gb2312"><METAHTTP-EQUIV="Pragma"CONTENT="no-cache"><METAHTTP-EQUIV="Cache-Control"CONTENT="no-cache"><METAHTTP-EQUIV="Expires"CONTENT="0"></head><body><formmethod=postaction="check.jsp"><table><tr><tdalign=left>系统产生的认证码:</td><td><imgborder=0src="image.jsp"></td></tr><tr><tdalign=left>输入上面的认证码:</td><td><inputtype=textname=randmaxlength=4value=""></td></tr><tr><tdcolspan=2align=center><inputtype=submitvalue="提交检测"></td></tr></form></body></html>-----------------验证的页面----------check.jsp<%@pagecontentType="text/html;charset=gb2312"language="java"import="java.sql.*"errorPage=""%><html><head><title>认证码验证页面</title><metahttp-equiv="Content-Type"content="text/html;charset=gb2312"><METAHTTP-EQUIV="Pragma"CONTENT="no-cache"><METAHTTP-EQUIV="Cache-Control"CONTENT="no-cache"><METAHTTP-EQUIV="Expires"CONTENT="0"></head><body><%Stringrand=(String)session.getAttribute("rand");Stringinput=request.getParameter("rand");%>系统产生的认证码为:<%=rand%><br>您输入的认证码为:<%=input%><br><br><%if(rand.equals(input)){%><fontcolor=green>输入相同,认证成功!</font><%}else{%><fontcolor=red>输入不同,认证失败!</font><%}%></body></html>
解决方案九:
看看哪儿有问题?
解决方案十:
该回复于2010-12-23 14:42:09被版主删除
解决方案十一:
参考
解决方案十二:
请参考楼上的参考