Serious: Servlet.service () for Servlet JSP threw exception
Already been called Forthis response after searching online, add two words to the end of the JSP file that generates the CAPTCHA
Out.clear ();
out = Pagecontext.pushbody ();
===========================================================================tomcat5 JSP appears Getoutputstream () has Already been called for the cause of this response exception and resolution in the TOMCAT5 under the JSP is generally used in JSP in the output stream (such as output image verification code, file download, etc.), did not properly deal with the reasons for good. The reason for this is that after the JSP is compiled into a servlet in Tomcat, there is a code at the end of the function _jspservice (httpservletrequest request, httpservletresponse response)
Finally {
if
(_jspxfactory!= null)
_jspxfactory.releasepagecontext (_jspx_page_context);
}
This is where the object used in the JSP is freed, and Response.getwriter () is invoked because the method conflicts with Response.getoutputstream (). So this anomaly will appear. The method is simple. After using the OutputStream output stream, call the following 2 methods to resolve the problem:
Out.clear ();
out =
pagecontext.pushbody ();
Sample code:
OutputStream Os=response.getoutputstream ();
Os.write (New String ("True
" + "nownum=" + nownum+ "= ="). GetBytes ());
Os.flush ();
Os.close ();
Out.clear ();
out = Pagecontext.pushbody ();
--------------------------------------------------------------------------------------------------------------- -------------------when JSP prints a picture to the page, using Response.getoutputstream () will have this hint:
Java.lang.IllegalStateException:getOutputStream ()
has already been called for this response,
Will throw the exception reason one: the JSP default output stream is PrintWriter, that is, <%%> something other than the default output way, If you try to use Servletoutputstream in your JSP, you can cause an error. Why not go directly to the servlet output (the Replication service method), delete anything except the%><% (including HTML tags, spaces, carriage returns, etc.) It should be. This should be the case for such a situation, delete all the content between the%><% including spaces and line breaks, and finally to eliminate spaces and line breaks, preferably plus a response.reset (). Reason two: In the Java EE API Reference has this: Servletresponse's Getwriter () method throws this exception,
Illegalstateexception-if the Getoutputstream method has already been called
For this response object and its Getoutputstream () method throws this exception. Illegalstateexception-if the Getoutputstream method has already been to this called object and both of the function declarations have this kind of EI Ther this and getoutputstream () May is called to write the body, not both. Either this and getwriter () May is called to write the body and not both. The above explanation also explains why you should use the following looping format when writing pictures to a page
OutputStream Output=response.getoutputstream ();
while ((Len=in.read (b)) >0)
{
output.write (B,0,len);
}
Output.flush ();
Instead of putting Response.getoutputstream (). write () into the loop body