protected RequestDispatcher doGetRequestDispatcher(ServletContext servletContext, String path) {

    if (!PropsValues.DIRECT_SERVLET_CONTEXT_ENABLED) {
      return servletContext.getRequestDispatcher(path);
    }

    if ((path == null) || (path.length() == 0)) {
      return null;
    }

    if (path.charAt(0) != CharPool.SLASH) {
      throw new IllegalArgumentException("Path " + path + " is not relative to context root");
    }

    String contextPath = ContextPathUtil.getContextPath(servletContext);

    String fullPath = contextPath.concat(path);
    String queryString = null;

    int pos = fullPath.indexOf(CharPool.QUESTION);

    if (pos != -1) {
      queryString = fullPath.substring(pos + 1);

      fullPath = fullPath.substring(0, pos);
    }

    Servlet servlet = DirectServletRegistryUtil.getServlet(fullPath);

    if (servlet == null) {
      if (_log.isDebugEnabled()) {
        _log.debug("No servlet found for " + fullPath);
      }

      RequestDispatcher requestDispatcher = servletContext.getRequestDispatcher(path);

      return new DirectServletPathRegisterDispatcher(path, requestDispatcher);
    } else {
      if (_log.isDebugEnabled()) {
        _log.debug("Servlet found for " + fullPath);
      }

      return new DirectRequestDispatcher(servlet, queryString);
    }
  }
  @Override
  public PageContext getPageContext(
      Servlet servlet,
      ServletRequest servletRequest,
      ServletResponse servletResponse,
      String errorPageURL,
      boolean needsSession,
      int buffer,
      boolean autoflush) {

    if (autoflush) {
      buffer = _JSP_WRITER_BUFFER_SIZE;
    }

    PageContext pageContext =
        _jspFactory.getPageContext(
            servlet,
            servletRequest,
            servletResponse,
            errorPageURL,
            needsSession,
            buffer,
            autoflush);

    if (_DIRECT_SERVLET_CONTEXT_ENABLED) {
      String servletPath = (String) servletRequest.getAttribute(WebKeys.SERVLET_PATH);

      if (servletPath != null) {
        servletRequest.removeAttribute(WebKeys.SERVLET_PATH);

        ServletContext servletContext = pageContext.getServletContext();

        String contextPath = servletContext.getContextPath();

        DirectServletRegistryUtil.putServlet(contextPath.concat(servletPath), servlet);
      }
    }

    return new PageContextWrapper(pageContext);
  }
 protected void cacheServlet() throws Exception {
   DirectServletRegistryUtil.clearServlets();
 }