public static void dispatchInclude ( RequestDispatcher dispatcher , HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException , SkipPageException { final boolean isOutmostInclude = request . getAttribute ( IS_INCLUDED_REQUEST_ATTRIBUTE_NAME ) == null ; if ( logger . isLoggable ( Level . FINE ) ) logger . log ( Level . FINE , "request={0}, isOutmostInclude={1}" , new Object [ ] { request , isOutmostInclude } ) ; try { if ( isOutmostInclude ) request . setAttribute ( IS_INCLUDED_REQUEST_ATTRIBUTE_NAME , true ) ; dispatcher . include ( request , response ) ; if ( isOutmostInclude ) { // Set location header if set in attribute String location = ( String ) request . getAttribute ( LOCATION_REQUEST_ATTRIBUTE_NAME ) ; if ( location != null ) response . setHeader ( "Location" , location ) ; // Call sendError from here if set in attributes Integer status = ( Integer ) request . getAttribute ( STATUS_REQUEST_ATTRIBUTE_NAME ) ; if ( status != null ) { String message = ( String ) request . getAttribute ( MESSAGE_REQUEST_ATTRIBUTE_NAME ) ; if ( message == null ) { response . sendError ( status ) ; } else { response . sendError ( status , message ) ; } } } // Propagate effects of SkipPageException if ( request . getAttribute ( PAGE_SKIPPED_REQUEST_ATTRIBUTE_NAME ) != null ) throw ServletUtil . SKIP_PAGE_EXCEPTION ; } finally { if ( isOutmostInclude ) { request . removeAttribute ( IS_INCLUDED_REQUEST_ATTRIBUTE_NAME ) ; request . removeAttribute ( LOCATION_REQUEST_ATTRIBUTE_NAME ) ; request . removeAttribute ( STATUS_REQUEST_ATTRIBUTE_NAME ) ; request . removeAttribute ( MESSAGE_REQUEST_ATTRIBUTE_NAME ) ; // PAGE_SKIPPED_REQUEST_ATTRIBUTE_NAME not removed to propagate fully up the stack } } }
Performs the actual include supporting propagation of SkipPageException and sendError .