java.lang.IllegalStateException: Response has already been committed at org.apache.tomcat.core.HttpServletResponseFacade.sendError(HttpServletResponseFacade.java:157) at org.apache.jasper.runtime.JspServlet.unknownException(JspServlet.java:299) at org.apache.jasper.runtime.JspServlet.service(JspServlet.java, Compiled Code) at javax.servlet.http.HttpServlet.service(HttpServlet.java, Compiled Code) at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java, Compiled Code) at org.apache.tomcat.core.ContextManager.service(ContextManager.java, Compiled Code) at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java, Compiled Code) at org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java, Compiled Code) at java.lang.Thread.run(Thread.java, Compiled Code)
what does this error mean. can any one help
Randall Twede
Ranch Hand
Joined: Oct 21, 2000
Posts: 3901
posted
0
I ran into a problem like that using JDBC. I had to add these two lines(not directly following each other). con.setAutoCommit( false ); con.commit(); where con is: con = DriverManager.getConnection (URL,username,password);
I never took notes in college. That's how I got a 4.0 the first 2 years, and a 3.5 the second two years.
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
posted
0
Originally posted by Randall Twede: I ran into a problem like that using JDBC
Hmmmm. Would you expect an exception in an object called "HttpServletResponseFacade" because of a JDBC problem? In fact, there is no trace of JDBC in the entire stack trace. Whenever you call a method that needs to set response header fields, the HttpResponse object will generate an IllegalStateException if the response has already been committed. "Committed" means that the first chunk of the response -- including the header -- has already been sent off to the client because the buffer was full. Obviously, once you've sent off the header you can't modify it any more To fix this, make sure you do all your error checking, setting of content type etc. etc. before starting to produce content in earnest. In practice this means: move all this stuff to the very start of your JSP. HTH - Peter
[This message has been edited by Peter den Haan (edited February 16, 2001).]
Randall Twede
Ranch Hand
Joined: Oct 21, 2000
Posts: 3901
posted
0
Peter, I shouldnt stay up so late.
FrankInTheHouse
Greenhorn
Joined: Feb 16, 2001
Posts: 2
posted
0
Originally posted by Randall Twede: Peter, I shouldnt stay up so late.
Hi, I got this error when I wrote the following code in a html form: <jsp:useBean id="a_id" class="a_Bean_class" scope="request"> <jsp:setProperty name="formhandler" property="*"/> </jsp:useBean> I fixed it by defining a corresponding getter/setter for each property within the bean. There is a very good article on this topic in javaworld March 2000. Article is "advanced form processing using JSP" Good luck.
Frank Carver
Sheriff
Joined: Jan 07, 1999
Posts: 6913
posted
0
"FrankInTheHouse", Well I'm Frank, and I'm at the Ranch ... The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements. Thanks.
I have also seen the error message Included servlet error: 500 java.lang.IllegalStateException: Response has already been committed when I have been using jsp:include and have specified a page attribute (page=) that is not present (or my path is incorrectly specified for the page).
The problem is in the response being sent to the browser see the first few lines of the stack trace: java.lang.IllegalStateException: Response has already been committed at org.apache.tomcat.core.HttpServletResponseFacade.sendError HttpServletResponseFacade.java:157) at org.apache.jasper.runtime.JspServlet.unknownException(JspServlet.java:299)
The jsp is being evaluated and some output is being written to the (buffered) output stream. It is safe to change the page that is returned UP TO the point when the buffer is full and something actually gets sent to the client. At this point the HTTP header has been written and the reponse is considered 'committed'.<br>Going back to the stack trace, an unknown exception is being thrown, the app server tries to redirect to the error page (the call to 'sendError') but fails since it is no longer possible to change the page tyhat will be returned. I'd have to mess around with it a bit and it would be implementation dependant, but using the JSP directives to increase the buffer and remove auto-flushing might help. Note that this can also occur when RequestDispatcher.forward() is used. (ie forward to a new page that throws an exception,. but the page has been 'locked in' so it is not possible to redirect to the error page) [This message has been edited by David O'Meara (edited March 06, 2001).]