Package javax.servlet

Examples of javax.servlet.RequestDispatcher


    protected final String getDynamicQuery(String queryResource,
            HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        // get the dispatcher
        RequestDispatcher dispatcher = getServletContext()
                .getRequestDispatcher(queryResource);
        if (dispatcher == null) {
            throw new ServletException(
                    "Cannot get a RequestDispatcher for path: " + queryResource);
        }

        // set some useful information in the request
        request.setAttribute("path", ServletParameterUtils
                .getPathElements(request));

        // wrap the request in order to supply extra functionality (multiparm
        // form handling)
        CustomHttpServletRequestWrapper requestWrapper = new CustomHttpServletRequestWrapper(
                request, this.multipartSizeThreshold, this.multipartMaxSize,
                this.multipartRepositoryPath);

        // wrap our response, so we can capture the body (and the included
        // resource cannot mess with it)
        CustomHttpServletResponseWrapper responseWrapper = new CustomHttpServletResponseWrapper(
                response);

        // include the resource
        dispatcher.include(requestWrapper, responseWrapper);

        // and get the body
        String sql = responseWrapper.getBody();

        if (sql == null) {
View Full Code Here


     */
    private final void serveDefaultResource(String defaultResource,
            HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // get the dispatcher
        RequestDispatcher dispatcher = getServletContext()
                .getRequestDispatcher(defaultResource);
        if (dispatcher == null) {
            throw new ServletException(
                    "Cannot get a RequestDispatcher for path: "
                            + defaultResource);
        }
        dispatcher.forward(request, response);
    }
View Full Code Here

            // loop through operations
            for (Iterator i = this.operations.iterator(); i.hasNext();) {
                Operation operation = (Operation) i.next();

                // get the dispatcher
                RequestDispatcher dispatcher = ServletParameterUtils
                        .getRequestDispatcher(context, operation
                                .getResourceNameOrPath());

                // wrap our request in order to override the HTTP method
                RequestWrapper requestWrapper = new RequestWrapper(request,
                        operation.getHttpMethod());

                // if this is the last operation just forward the request
                if (!i.hasNext()) {
                    dispatcher.forward(requestWrapper, response);
                    break;
                }

                // wrap our response in order to capture its body
                ResponseWrapper responseWrapper = new ResponseWrapper(response);

                // otherwise process this operation
                dispatcher.include(requestWrapper, responseWrapper);

                // check for successful response
                int responseStatus = responseWrapper.getStatus();
                if (responseStatus < 200 || responseStatus > 299) {
                    throw new ServletException("Operation "
View Full Code Here

    }

    public static RequestDispatcher getRequestDispatcher(
            ServletContext context, String resourceNameOrPath)
            throws ServletException {
        RequestDispatcher dispatcher = context
                .getNamedDispatcher(resourceNameOrPath);
        if (dispatcher == null) {
            dispatcher = context.getRequestDispatcher(resourceNameOrPath);
        }
        if (dispatcher == null) {
View Full Code Here

  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String key = request.getParameter("key");
    UserEntity user = getDao().getUserDao().getByKey(key);
    if (user == null || user.isDisabled()) {
      RequestDispatcher dispatcher = getServletContext()
          .getRequestDispatcher("/forgotPasswordFail.vm");
      dispatcher.forward(request,response);
    }
    else {
      user.setForgotPasswordKey(null);
      getDao().getUserDao().save(user);
      HttpSession session = request.getSession(true);
View Full Code Here

  public int getRemotePort() {
    return remotePort;
  }

  public RequestDispatcher getRequestDispatcher(String uri) {
    RequestDispatcher rd = registrations.getRequestDispatcher(uri);
    return rd;
  }
View Full Code Here

    try
    {
      String servlet = request.getHeader(SERVLET_HEADER);
      if (servlet == null)
        throw new IllegalArgumentException("Missing header: " + SERVLET_HEADER);
      RequestDispatcher requestDispatcher = getServletContext().getNamedDispatcher(servlet);
      if (requestDispatcher == null)
        throw new IllegalStateException("Could not found servlet with name " + servlet);
      request.getSession().setHandler(servlet);
      requestDispatcher.forward(request, null);
    }   
    catch (Throwable e)
    {
      sendError(request, e);
    }
View Full Code Here

    else {
      path = "/WEB-INF/" + path.replace('.', '/') + getExt();
    }

    // 执行 Forward
    RequestDispatcher rd = req.getRequestDispatcher(path);
    if (rd == null)
      throw Lang.makeThrow("Fail to find Forward '%s'", path);
    // Do rendering
    rd.forward(req, resp);
  }
View Full Code Here

  public void dispatch(String path)
    throws IOException
  {
    try {
      //_request.getRequestDispatcher(path).include(_request, _response);
      RequestDispatcher rd = _request.getRequestDispatcher(path);

      if (rd == null)
        throw new FacesException(L.l("'{0}' is an unknown dispatcher.",
                                     path));

     
      rd.forward(_request, _response);
    } catch (ServletException e) {
      throw new FacesException(e);
    }
  }
View Full Code Here

    if (uri == null) {
      log.warning(L.l("FormLogin: session has timed out for session '{0}'",
                      req.getSession().getId()));
     
      RequestDispatcher disp = request.getRequestDispatcher("/");
      if (disp != null) {
        disp.forward(request, response);
        return;
      }
      else {
        throw new ServletException(L.l("Session has timed out for form authentication, no forwarding URI is available.  Either the login form must specify j_uri or the session must have a saved URI."));
      }
    }

    if (uri.indexOf('\n') >= 0 || uri.indexOf('\r') >= 0)
      throw new ServletException(L.l("Forwarding URI '{0}' is invalid.",
                                     uri));

    String uriPwd = req.getRequestURI();
    int p = uriPwd.indexOf("/j_security_check");
    if (p >= 0)
      uriPwd = uriPwd.substring(0, p + 1);
   
    if (uri.length() == 0) {
    }
    else if (uri.charAt(0) == '/')
      uri = req.getContextPath() + uri;
    else if (uri.indexOf(':') >= 0 &&
             (uri.indexOf(':') < uri.indexOf('/') ||
              uri.indexOf('/') < 0)) {
    }
    else {
      uri = uriPwd + uri;
    }

    // The spec says that a successful login uses a redirect.  Resin
    // adds a configuration option to allow an internal forward
    // if the URL is in the same directory.
   
    // Logins to POST pages need to use an internal forward.
    // Most GETs will want a redirect.
    boolean useInternalForward = login.getInternalForward();
   
    if (useInternalForward
        && uri.startsWith(uriPwd)
        && uri.indexOf('/', uriPwd.length() + 1) < 0) {
      WebApp newApp = (WebApp) webApp.getContext(uri);
      String suffix = uri.substring(newApp.getContextPath().length());
     
      // force authorization of the page because the normal forward()
      // bypasses authorization
      RequestDispatcher disp = newApp.getLoginDispatcher(suffix);
      if (disp != null) {
        disp.forward(req, res);
        return;
      }
    }
   
    res.sendRedirect(res.encodeRedirectURL(uri));
View Full Code Here

TOP

Related Classes of javax.servlet.RequestDispatcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.