commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: DBCP "Statement already closed .... how?"
Date Wed, 26 Nov 2003 03:49:11 GMT
Quoting Anthony Presley <>:

> Thank you Dirk ..... where do you live?  I owe you a Pizza.
> This did, in fact, solve almost all of my problems.  Subtle [to me].
> However, I have a remaining issue, and I've narrowed it down to the
> following lines of code.  I'll post in the tomcat user group, but
> thought someone here might have a pearl of wisdom.
> Nine times out of ten, multiple requests work perfectly.  However, in
> the one time out of ten that it doesn't, my code is throwing an
> Exception with this:
>       try {
>         if (rd != null)
>           rd.forward(req, res);
>         else {
>           log("RD is NULL, MAJOR ERROR");
>         }
>       } catch (ServletException e) {
>         log("5ERROR ServletException: " + e.getMessage());
>         e.printStackTrace();
>       } catch ( e) {
>         log("5ERROR " + e.getMessage());
>         e.printStackTrace();
>       } catch (Exception e) {
>         log("5ERROR Exception: " + e.getMessage());
>         e.printStackTrace();
>       }
> Doing a reload on it, it works fine.  IE, what is being sent (the URL)
> does start with a "/", and rd is NOT null (neither are req or res).
> The Error is: 
> 	5ERROR Exception: Cannot forward after response has been commit

It means you tried to call RequestDispatcher.forward() after the current
response has been committed :-).

To understand what's really happening, you need to be a little bit familiar with
how servlets work.  When you start writing to a response page, the output you
write is buffered, up to the point where the buffer size has been exceeded. 
Prior to that point, you can call forward() -- which, among other things,
erases any buffered output so that the new resource or page can write the entre
content of the response.

However, if you've already written more characters than the size of the output
buffer, the HTTP headers (and the first part of the response) are actually sent
to the client.  After that point, the response is considered to be "committed"
and you can no longer do a RequestDispatcher.forward() call.

So, how big is the page buffer?  Ah, there's the rub ... it's not specified, so
it varies by container.  However, you can control it by calling
response.setBufferSize() if you are writing directly from a servlet, or using
the "buffer" attribute on the <%@ page %> directive if you're using JSP.  You
need to ensure that you haven't already written more characters than the buffer
size before you execute the forward() call.

Note that this kind of problem would never occur if you were using an MVC-based
framework like Struts <>, because the business
logic that processed the incoming form submit would never output anything to
the response -- it would merely perform the required processing, then forward()
to a servlet or JSP page to create the actual output.

Craig McClanahan

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message