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:com.netcracker.financeapp.controller.income.IncomeServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    ArrayList<String> incomeTypeList = typeService.getIncomeTypeNames();
    request.setAttribute("incomeTypeList", incomeTypeList);

    ArrayList<String> bankCardNumbers = bankCardService.getBankCardNumbers();
    request.setAttribute("toList", bankCardNumbers);

    ArrayList<String> agentNames = agentService.getAgentNames();
    request.setAttribute("fromList", agentNames);

    request.getRequestDispatcher("income/incomePage.jsp").forward(request, response);

}

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

/**
 *
 * @param request servlet request/*from  w  w  w  . ja  va 2s  .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:com.parallax.server.blocklyprop.servlets.ProfileServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    User user = BlocklyPropSecurityUtils.getUserInfo();
    req.setAttribute("id", user.getId());
    req.setAttribute("email", user.getEmail());
    req.setAttribute("screenname", user.getScreenname());
    if ("local".equals(user.getAuthenticationSource())) {
        req.getRequestDispatcher("/WEB-INF/servlet/profile/profile.jsp").forward(req, resp);
    } else {// w  w  w.  ja  v  a 2s  . c o m
        req.setAttribute("authentication-source", user.getAuthenticationSource());
        req.getRequestDispatcher("/WEB-INF/servlet/profile/profile-oauth.jsp").forward(req, resp);
    }
}

From source file:ch.entwine.weblounge.kernel.http.WelcomeFileFilterServlet.java

/**
 * {@inheritDoc}//from   ww  w.  j ava  2 s .c o m
 *
 * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

    if (req.getPathInfo() != null && "/".equals(req.getPathInfo())) {
        if (!welcomeFileList.isEmpty()) {
            // use the first one for now:
            for (String welcomeFile : welcomeFileList) {
                String file = welcomeFile;
                if (welcomeFile.startsWith("/"))
                    file = welcomeFile.substring(1);
                RequestDispatcher dispatcher = req.getRequestDispatcher(file);
                // TODO: check if resource exists before forwarding
                dispatcher.forward(req, res);
                return;
            }
        } else {
            req.getRequestDispatcher(req.getServletPath() + "/resources/index.html").forward(req, res);
            // Tomcat also defaults to index.jsp
            return;
        }
    } else {
        // no welcome file, trying to forward to remapped resource:
        // /resources"+req.getPathInfo()
        req.getRequestDispatcher(req.getServletPath() + "/resources" + req.getPathInfo()).forward(req, res);
    }
}

From source file:com.xpn.xwiki.web.ActionFilter.java

/**
 * {@inheritDoc}/*from www  . ja  va  2s. c  o m*/
 * 
 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
 */
@SuppressWarnings("unchecked")
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    // Only HTTP requests can be dispatched.
    if (request instanceof HttpServletRequest
            && !Boolean.valueOf((String) request.getAttribute(ATTRIBUTE_ACTION_DISPATCHED))) {
        HttpServletRequest hrequest = (HttpServletRequest) request;
        Enumeration<String> parameterNames = hrequest.getParameterNames();
        while (parameterNames.hasMoreElements()) {
            String parameter = parameterNames.nextElement();
            if (parameter.startsWith(ACTION_PREFIX)) {
                String targetURL = getTargetURL(hrequest, parameter);
                RequestDispatcher dispatcher = hrequest.getRequestDispatcher(targetURL);
                if (dispatcher != null) {
                    LOG.debug("Forwarding request to " + targetURL);
                    request.setAttribute(ATTRIBUTE_ACTION_DISPATCHED, "true");
                    dispatcher.forward(hrequest, response);
                    // Allow multiple calls to this filter as long as they are not nested.
                    request.removeAttribute(ATTRIBUTE_ACTION_DISPATCHED);
                    // If the request was forwarder to another path, don't continue the normal processing chain.
                    return;
                }
            }
        }
    }
    // Let the request pass through unchanged.
    chain.doFilter(request, response);
}

From source file:com.centurylink.mdw.hub.servlet.RestServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    CodeTimer timer = new CodeTimer("RestServlet.doPost()", true);

    if (request.getPathInfo() != null && request.getPathInfo().startsWith("/SOAP")) {
        // forward to SOAP servlet
        RequestDispatcher requestDispatcher = request.getRequestDispatcher(request.getPathInfo());
        requestDispatcher.forward(request, response);
        return;/*from   w  w  w. j a v  a2 s. co m*/
    }

    Map<String, String> metaInfo = buildMetaInfo(request);
    try {
        String responseString = handleRequest(request, response, metaInfo);
        response.getOutputStream().print(responseString);
    } catch (ServiceException ex) {
        logger.severeException(ex.getMessage(), ex);
        response.setStatus(ex.getCode());
        response.getWriter().println(createErrorResponseMessage(request, metaInfo, ex));
    } finally {
        timer.stopAndLogTiming("");
    }
}

From source file:com.google.ie.web.interceptor.LoginInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    // Check auth token and return true if found
    // Check for user object in session
    if (null == request.getSession().getAttribute("user")) {
        // Forward for authentication
        int authStatus = userController.authenticationCheckForOpenId(request, response, null);
        if (authStatus == 1) {
            return true;
        }/*from w w w  .  java 2s .co  m*/
        /** Redirect to home page */
        request.getRequestDispatcher("/").forward(request, response);
        return false;

    }
    return true;

}

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;//from   w  ww.j a v  a  2 s .c om
    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:io.muic.ooc.webapp.servlet.AddServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    System.out.println("Add " + username);
    System.out.println("Add " + password);
    if (StringUtils.isBlank(username) && StringUtils.isBlank(password)) {
        String error = "Username or password is missing.";
        request.setAttribute("error", error);
        RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/add.jsp");
        rd.include(request, response);/*  w  w  w. j a va 2s  .c  om*/
    } else {
        try {
            if (mySQLService.findOne(username)) {
                String error = "This Username is already exist.";
                request.setAttribute("error", error);
                RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/add.jsp");
                rd.include(request, response);
            } else {
                String digest = DigestUtils.md5Hex(password);
                mySQLService.addDataBase(username, digest);
                response.sendRedirect("/");
            }
        } catch (Exception e) {

        }

    }
}

From source file:IncludeServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();

    out.println("<html>");
    out.println("<head>");
    out.println("<title>Include Servlet</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Welcome To Our Universe</h1>");
    out.println("Imagine the rest of the page here.<br><br>");
    //Include the copyright information
    RequestDispatcher dispatcher = request.getRequestDispatcher("/CopyRight");
    dispatcher.include(request, response);

    out.println("</body>");
    out.println("</html>");

    out.close();/*  w  ww . ja v a 2s  .co  m*/

}