try {
request.lockSession();
hres.setStatus(statusCode);
ServletContext servletContext =
request.getContext().getServletContext();
ApplicationDispatcher dispatcher = (ApplicationDispatcher)
servletContext.getRequestDispatcher(errorPage.getLocation());
if (hres.isCommitted()) {
// Response is committed - including the error page is the
// best we can do
dispatcher.include(sreq, sres);
} else {
// Reset the response (keeping the real error code and message)
response.resetBuffer(true);
dispatcher.dispatch(sreq, sres, DispatcherType.ERROR);
// If we forward, the response is suspended again
response.setSuspended(false);
}
sres.flushBuffer();