Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48661
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 8 Mar 2010 18:58:28 +0000 (18:58 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 8 Mar 2010 18:58:28 +0000 (18:58 +0000)
If the response has been committed, include the error page like Jasper does

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@920449 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/core/StandardHostValve.java

index c853705..6ebf5d4 100644 (file)
@@ -416,18 +416,25 @@ final class StandardHostValve
         request.setPathInfo(errorPage.getLocation());
 
         try {
-            // Reset the response (keeping the real error code and message)
-            response.resetBuffer(true);
-
             // Forward control to the specified location
             ServletContext servletContext =
                 request.getContext().getServletContext();
             RequestDispatcher rd =
                 servletContext.getRequestDispatcher(errorPage.getLocation());
-            rd.forward(request.getRequest(), response.getResponse());
 
-            // If we forward, the response is suspended again
-            response.setSuspended(false);
+            if (response.isCommitted()) {
+                // Response is committed - including the error page is the
+                // best we can do 
+                rd.include(request.getRequest(), response.getResponse());
+            } else {
+                // Reset the response (keeping the real error code and message)
+                response.resetBuffer(true);
+
+                rd.forward(request.getRequest(), response.getResponse());
+
+                // If we forward, the response is suspended again
+                response.setSuspended(false);
+            }
 
             // Indicate that we have successfully processed this custom page
             return (true);