Example usage for javax.servlet.http HttpServletRequest getRequestDispatcher

List of usage examples for javax.servlet.http HttpServletRequest getRequestDispatcher

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getRequestDispatcher.

Prototype

public RequestDispatcher getRequestDispatcher(String path);

Source Link

Document

Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.

Usage

From source file:util.JSPUtil.java

public static void naytaJSP(HttpServletRequest request, HttpServletResponse response, String jspsivu) {
    RequestDispatcher dispatcher = null;
    //dispatcher = request.getRequestDispatcher("WEB-INF/jsp/muokkaatankki.jsp");
    dispatcher = request.getRequestDispatcher(jspsivu);
    try {/*ww w  . j  a  va2 s .  co  m*/
        dispatcher.forward(request, response);
    } catch (ServletException ex) {
        Logger.getLogger(JSPUtil.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(JSPUtil.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:info.magnolia.cms.util.JSPIncludeUtil.java

public static String get(String jsp, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    ImportResponseWrapper wrappedResponse = new ImportResponseWrapper(response);
    request.getRequestDispatcher(jsp).include(request, wrappedResponse);
    return wrappedResponse.getString();
}

From source file:com.act.web.includeservletasstring.IncludeServletAsString.java

static public String invokeServletAndReturnAsString(String url, HttpServletRequest servletRequest,
        HttpServletResponse servletResponse) throws IOException, ServletException {

    if (log.isDebugEnabled()) {
        log.debug("Including url \"" + url + "\"...");
    }//w ww .j  a va  2  s  .c  o  m

    RequestDispatcher requestDispatcher = servletRequest.getRequestDispatcher(url);

    if (requestDispatcher == null) {
        IllegalArgumentException iae = new IllegalArgumentException(
                "Failed to get RequestDispatcher for url: " + url);
        log.error(iae.getMessage(), iae);
        throw iae;
    }

    BufferedResponse bufferedResponse = new BufferedResponse(servletResponse);

    requestDispatcher.include(servletRequest, bufferedResponse);

    byte[] buffer = bufferedResponse.getBufferAsByteArray();
    if (log.isDebugEnabled()) {
        log.debug("Buffer returned with " + buffer.length + " bytes.");
    }

    String bufferString = new String(buffer, servletResponse.getCharacterEncoding());

    return bufferString;
}

From source file:net.incrementalism.tooter.ProfileServlet.java

private static void displayProfile(User user, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    request.setAttribute("user", user);
    request.setAttribute("following", loadUsersFollowedBy(user.getUserName()));
    request.setAttribute("toots", loadTootsFor(user.getUserName()));
    request.getRequestDispatcher("/profile.jsp").include(request, response);
}

From source file:catalogo.Main.java

/**
 * Redirige la navegacin web a la pgina indicada en newUrl, pasndole en
 * request los datos que necesite/*from   w ww.j  a va2s  . c  o  m*/
 *
 * @param newUrl
 * @param request
 * @param response
 */
private static void redirectTo(String newUrl, HttpServletRequest request, HttpServletResponse response) {
    try {
        RequestDispatcher dispatcher = null;
        dispatcher = request.getRequestDispatcher(newUrl);
        dispatcher.forward(request, response);
    } catch (ServletException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.lm.lic.manager.util.GenUtil.java

/**
 * @param request/*from ww w .  jav  a2s .c o  m*/
 * @param response
 * @throws ServletException
 * @throws IOException
 */
public static void toHell(HttpServletRequest request, HttpServletResponse response, String hellView)
        throws ServletException, IOException {
    javax.servlet.RequestDispatcher rd = request.getRequestDispatcher(hellView);
    rd.forward(request, response);
}

From source file:com.feilong.servlet.http.RequestUtil.java

/**
 * ? {@link RequestDispatcher} ??,Servlet??????.
 * /* w  ww . j  av a2  s.co m*/
 * <p>
 * Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server.<br>
 * This method allows one servlet to do preliminary processing of a request and another resource to generate the response.
 * </p>
 * 
 * <p>
 * For a <code>RequestDispatcher</code> obtained via <code>getRequestDispatcher()</code>, the <code>ServletRequest</code> object has its
 * path elements and parameters adjusted to match the path of the target resource.
 * </p>
 * 
 * <p>
 * <code>forward</code> should be called before the response has been committed to the client (before response body output has been
 * flushed). If the response already has been committed, this method throws an <code>IllegalStateException</code>. Uncommitted output in
 * the response buffer is automatically cleared before the forward.
 * </p>
 * 
 * <p>
 * The request and response parameters must be either the same objects as were passed to the calling servlet's service method or be
 * subclasses of the {@link ServletRequestWrapper} or {@link ServletResponseWrapper} classes that wrap them.
 * </p>
 * 
 * @param path
 *            the path
 * @param request
 *            a {@link ServletRequest} object that represents the request the client makes of the servlet
 * @param response
 *            a {@link ServletResponse} object,that represents the response the servlet returns to the client
 * @since 1.2.2
 */
public static void forward(String path, HttpServletRequest request, HttpServletResponse response) {
    RequestDispatcher requestDispatcher = request.getRequestDispatcher(path);
    try {
        requestDispatcher.forward(request, response);
    } catch (ServletException | IOException e) {
        LOGGER.error("", e);
        throw new RequestException(e);
    }
}

From source file:com.feilong.servlet.http.RequestUtil.java

/**
 *  {@link RequestDispatcher} ??????,????.
 * /*  www .  j  a  va 2 s.c o m*/
 * <p>
 * Includes the content of a resource (servlet, JSP page,HTML file) in the response. <br>
 * In essence, this method enables programmatic server-side includes.
 * </p>
 * 
 * <p>
 * :?Servlet????????,???.<br>
 * The {@link ServletResponse} object has its path elements and parameters remain unchanged from the caller's. <br>
 * The included servlet cannot change the response status code or set headers; any attempt to make a change is ignored.
 * </p>
 * 
 * <p>
 * The request and response parameters must be either the same objects as were passed to the calling servlet's service method or be
 * subclasses of the {@link ServletRequestWrapper} or {@link ServletResponseWrapper} classes that wrap them.
 * </p>
 * 
 * @param path
 *            the path
 * @param request
 *            a {@link ServletRequest} object,that contains the client's request
 * @param response
 *            a {@link ServletResponse} object,that contains the servlet's response
 * @see javax.servlet.RequestDispatcher#include(ServletRequest, ServletResponse)
 * @see "org.springframework.web.servlet.ResourceServlet"
 * @since 1.2.2
 */
public static void include(String path, HttpServletRequest request, HttpServletResponse response) {
    RequestDispatcher requestDispatcher = request.getRequestDispatcher(path);
    try {
        requestDispatcher.include(request, response);
    } catch (ServletException | IOException e) {
        LOGGER.error("", e);
        throw new RequestException(e);
    }
}

From source file:net.incrementalism.tooter.LogInServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.getRequestDispatcher("/logIn.jsp").include(request, response);
}

From source file:Main.java

protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    RequestDispatcher dispatcher = request.getRequestDispatcher("/p.jsp");

    dispatcher.forward(request, response);
}