Example usage for javax.servlet RequestDispatcher forward

List of usage examples for javax.servlet RequestDispatcher forward

Introduction

In this page you can find the example usage for javax.servlet RequestDispatcher forward.

Prototype

public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException;

Source Link

Document

Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server.

Usage

From source file:com.siriusit.spezg.multilib.jsf.login.LoginBean.java

public String logIn() throws IOException, ServletException {
    ExternalContext externalContext = context.getExternalContext();
    ServletRequest servletRequest = (ServletRequest) externalContext.getRequest();
    RequestDispatcher dispatcher = servletRequest.getRequestDispatcher("/j_spring_security_check");
    dispatcher.forward((ServletRequest) externalContext.getRequest(),
            (ServletResponse) externalContext.getResponse());
    context.responseComplete();/*w w w  .  j  a va 2s  .c om*/
    return null;
}

From source file:com.gigglinggnus.controllers.AdminViewAppointmentsController.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    EntityManager em = (EntityManager) request.getSession().getAttribute("em");

    Clock clk = (Clock) (request.getSession().getAttribute("clock"));

    RequestDispatcher rd = request.getRequestDispatcher("/admin/view-apmts.jsp");
    rd.forward(request, response);
}

From source file:org.wallride.web.support.BlogLanguageRewriteMatch.java

@Override
public boolean execute(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    UrlPathHelper urlPathHelper = new UrlPathHelper();
    String originalPath = urlPathHelper.getLookupPathForRequest(request);

    String rewritePath = originalPath.replaceAll("^/" + blogLanguage.getLanguage() + "/", "/");
    matchingUrl = rewritePath;// www.j  ava 2 s  . co m
    logger.debug(originalPath + " => " + rewritePath);

    request.setAttribute(BlogLanguageMethodArgumentResolver.BLOG_LANGUAGE_ATTRIBUTE, blogLanguage);

    RequestDispatcher rd = request.getRequestDispatcher(urlPathHelper.getServletPath(request) + rewritePath);
    rd.forward(request, response);
    return true;
}

From source file:cz.muni.fi.myweb1.RestaurantServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String name = request.getAttribute("username").toString();
    String password = request.getAttribute("password").toString();

    /*  //w ww. ja  v a  2  s. c  om
       response.setContentType("text/html;charset=utf-8");
    PrintWriter out = response.getWriter();
    out.println("<h1>Text</h1><pre>generated directly from servlet code");
    out.println("serverInfo=" + getServletContext().getServerInfo());
    out.println("parameters: "+ name + " " + password);
       */

    if (loginFacade.login(name, password)) {
        request.getSession().setAttribute("username", name);
        RequestDispatcher rd = request.getRequestDispatcher("/outline.jsp");
        rd.forward(request, response);
    }

    else {
        //TODO error
    }

    /*
     try {
        List<Restaurant> list = myFacade.topRestaurants();
        request.getSession().setAttribute("restList", list);
        RequestDispatcher rd=request.getRequestDispatcher("/outline.jsp");
        rd.forward(request, response);
     } catch (Exception e) {
    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
     }
      */
}

From source file:org.apache.struts.chain.servlet.PerformForward.java

/**
 * <p>Perform the appropriate processing on the specified
 * <code>ForwardConfig</code>.</p>
 *
 * @param context The context for this request
 * @param forwardConfig The forward to be performed
 *///from w w w .  j  a va 2 s  .c om
protected void perform(Context context, ForwardConfig forwardConfig) throws Exception {

    ServletWebContext swcontext = (ServletWebContext) context;
    String forwardPath = forwardConfig.getPath();
    String uri = null;

    ModuleConfig moduleConfig = (ModuleConfig) context.get(getModuleConfigKey());
    // Resolve module-relative paths
    if (forwardPath.startsWith("/")) {
        uri = RequestUtils.forwardURL(swcontext.getRequest(), forwardConfig, moduleConfig);
    } else {
        uri = forwardPath;
    }

    // Get the underlying request in the case of a multipart wrapper
    HttpServletRequest request = swcontext.getRequest();
    if (request instanceof MultipartRequestWrapper) {
        request = ((MultipartRequestWrapper) request).getRequest();
    }

    // Perform redirect or forward
    if (forwardConfig.getRedirect()) {
        if (uri.startsWith("/")) {
            uri = request.getContextPath() + uri;
        }
        swcontext.getResponse().sendRedirect(swcontext.getResponse().encodeRedirectURL(uri));
    } else {
        RequestDispatcher rd = swcontext.getContext().getRequestDispatcher(uri);
        rd.forward(request, swcontext.getResponse());
    }

}

From source file:cn.imethan.common.security.handle.AccessDeniedHandlerImpl.java

public void handle(HttpServletRequest request, HttpServletResponse response,
        AccessDeniedException accessDeniedException) throws IOException, ServletException {
    if (!response.isCommitted()) {
        if (errorPage != null) {
            // Put exception into request scope (perhaps of use to a view)
            request.setAttribute(WebAttributes.ACCESS_DENIED_403, accessDeniedException);

            // Set the 403 status code.
            response.setStatus(HttpServletResponse.SC_FORBIDDEN);

            // forward to error page.
            RequestDispatcher dispatcher = request.getRequestDispatcher(errorPage);
            dispatcher.forward(request, response);
        } else {/*w w w .  j a  va2  s  .  co m*/
            response.sendError(HttpServletResponse.SC_FORBIDDEN, accessDeniedException.getMessage());
        }
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.SparqlQueryBuilderServlet.java

private void doHelp(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    req.setAttribute("title", "SPARQL Query Builder");
    req.setAttribute("bodyJsp", "/admin/sparql.jsp");

    RequestDispatcher rd = req.getRequestDispatcher("/" + Controllers.BASIC_JSP);
    rd.forward(req, res);
}

From source file:com.liulangf.pattern.gof.behavioral.chain.jakarta.simple.ForwardCommand.java

/**
 * <p>Execute the command.</p>
 *
 * @param context The {@link Context} we are operating on
 * @return <code>false</code> so that processng will continue
 * @throws Exception If an error occurs during execution.
 *//*from w w  w.  jav  a  2s  .  c om*/
public boolean execute(Context context) throws Exception {

    String uri = getForward(context);
    if (uri != null) {
        if (log.isDebugEnabled()) {
            log.debug("Forwarding to " + uri);
        }
        ServletWebContext swcontext = (ServletWebContext) context;
        RequestDispatcher rd = swcontext.getContext().getRequestDispatcher(uri);
        rd.forward(swcontext.getRequest(), swcontext.getResponse());
        return true;
    } else {
        if (log.isDebugEnabled()) {
            log.debug("No forward found");
        }
        return false;
    }
}

From source file:com.gigglinggnus.controllers.AdminViewAppointmentsController.java

/**
 *
 * @param request servlet request/*from w  ww  .  ja v  a2s .co  m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    EntityManager em = (EntityManager) request.getSession().getAttribute("em");

    Clock clk = (Clock) (request.getSession().getAttribute("clock"));

    String userId = request.getParameter("username");
    User user = em.find(User.class, userId);

    List<Appointment> appointments = user.getAppointments();
    request.setAttribute("appointments", appointments);

    RequestDispatcher rd = request.getRequestDispatcher("/admin/view-apmts.jsp");
    rd.forward(request, response);
}

From source file:de.highbyte_le.weberknecht.security.filters.NameBasedLoginPageForwardFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (logger.isDebugEnabled())
        logger.debug("doFilter() - start");

    boolean forward = true;

    if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
        logger.error("servlet request is no HTTP servlet request");
    } else {/*from  w w w. ja va2s  .co  m*/
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpSession session = httpRequest.getSession();

        UserAuthentication userAuthentication = (UserAuthentication) session.getAttribute("user_auth");
        if (userAuthentication != null && userAuthentication.isAuthenticated()) //user is logged in
            forward = false;
        else if (!isUserServlet(httpRequest.getServletPath())) //servlet is not protected
            forward = false;
    }

    if (forward) {
        request.setAttribute("de.highbyte_le.weberknecht.login.status", "failed");

        logger.debug("doFilter() - forward to login page");
        RequestDispatcher rd = request.getRequestDispatcher(loginPage);
        rd.forward(request, response);
    } else {
        logger.debug("doFilter() - Continue with filter chain");
        chain.doFilter(request, response);
    }
}