boolean customServletPath = dispatcherServletPath != null;
String theServletPath = customServletPath ? dispatcherServletPath : "/";
ServletContext sc = super.getServletContext();
RequestDispatcher rd = dispatcherServletName != null
? sc.getNamedDispatcher(dispatcherServletName)
: sc.getRequestDispatcher((theServletPath + pathInfo).replace("//", "/"));
if (rd == null) {
String errorMessage = "No RequestDispatcher can be created for path " + pathInfo;
if (dispatcherServletName != null) {
errorMessage += ", dispatcher name: " + dispatcherServletName;
}
throw new ServletException(errorMessage);
}
try {
for (Map.Entry<String, String> entry : redirectAttributes.entrySet()) {
request.setAttribute(entry.getKey(), entry.getValue());
}
HttpServletRequestFilter servletRequest =
new HttpServletRequestFilter(request, pathInfo, theServletPath, customServletPath);
rd.forward(servletRequest, response);
} catch (Throwable ex) {
throw new ServletException("RequestDispatcher for path " + pathInfo + " has failed");
}
}