但是一出来有验证码的页面,后台就会报错:
信息: Server startup in 13157 ms
2008-01-09 21:35:40,390 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/mi].[jsp]] - Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:601)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:196)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:185)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:116)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImp
在网上查了就是getOutputStream()方法和getWriter()方法只能用一个。但是我没有找到在哪里又调用了getWriter()方法。也不知道怎么改动,这么老是报错心里可不舒服。
最佳答案
具体的原因就是 文件代码如下: OutputStream o=response.getOutputStream(); |
out.clear();
out = pageContext.pushBody();
// 输出图象到页面
ImageIO.write(image, "JPEG", response.getOutputStream());
产生这样的异常原因:是web容器生成的servlet代码中有out.write(""),这个和JSP中调用的response.getOutputStream()产生冲突.即Servlet规范说明,不能既调用response.getOutputStream(),又调用response.getWriter(),无论先调用哪一个,在调用第二个时候应会抛出IllegalStateException,因为在jsp中,out变量实际上是通过response.getWriter得到的,你的程序中既用了response.getOutputStream,又用了out变量,故出现以上错误。