I'm trying to include a jsp page from a servlet:
RequestDispatcher rd = ctx.getRequestDispatcher( jspPage );
rd.include( req, wrapper );
But I'm getting the following exception:
java.lang.IllegalStateException: Cannot forward after response has been committed
The problem is with a JSP page that specifies its own default error page through the JSP error tag. The JSP error page can also throw an exception which will trickle up to the application level error page specified in web.xml. So when the jsp page that I am trying to include throws an exception, and the error page throws an exception as well, the include fails.
I have to handle this case gracefully because I am including user-written modules on a page and an erroneous module should display the exception to the user rather than bomb with the IllegalStateException. Any ideas?