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.bank_card.BankCardServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    ArrayList<String> bankCardNumbers = bankCardService.getBankCardNumbers();
    request.setAttribute("cardList", bankCardNumbers);

    String currentCard = request.getParameter("cardListVal");
    if (currentCard != null && currentCard != "Select Card") {

        BankCard currCard = bankCardService.getBankCardByNumber(currentCard);
        request.setAttribute("cardNumber", currCard.getCardNumber());
        request.setAttribute("currentAmount", currCard.getAmount());
        request.setAttribute("ownerName", currCard.getOwnerName());
        request.setAttribute("ownerSurname", currCard.getOwnerSurname());
        request.setAttribute("expireMonth", currCard.getExpireMonth());
        request.setAttribute("expireYear", currCard.getExpireYear());
        request.setAttribute("cvv", currCard.getCvv());
    }//from   w  w w .j a va 2s . c om
    request.setAttribute("clearCard", "Select Card");
    request.getRequestDispatcher("bankCard/bankCardPage.jsp").forward(request, response);

}

From source file:com.tubes2.FileUploadHandler.FileUploadHandler.java

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

    //process only if its multipart content
    if (ServletFileUpload.isMultipartContent(request)) {
        try {//from   w w w. ja v a 2 s.c o  m
            List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);

            for (FileItem item : multiparts) {
                if (!item.isFormField()) {
                    String name = new File(item.getName()).getName();
                    item.write(new File(UPLOAD_DIRECTORY + File.separator + name));
                }
            }

            //File uploaded successfully
            request.setAttribute("message", "File Uploaded Successfully");
        } catch (Exception ex) {
            request.setAttribute("message", "File Upload Failed due to " + ex);
        }

    } else {
        request.setAttribute("message", "Sorry this Servlet only handles file upload request");
    }

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

}

From source file:br.com.flucianofeijao.security.JsfLoginUrlAuthenticationEntryPoint.java

/**
 * Performs the redirect (or forward) to the login form URL.
 *///from   w  w w  . j a va 2  s .co  m
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {

    String redirectUrl = null;

    if (useForward) {

        if (forceHttps && "http".equals(request.getScheme())) {
            // First redirect the current request to HTTPS.
            // When that request is received, the forward to the login page will be used.
            redirectUrl = buildHttpsRedirectUrlForRequest(request);
        }

        if (redirectUrl == null) {
            String loginForm = determineUrlToUseForThisRequest(request, response, authException);

            if (logger.isDebugEnabled()) {
                logger.debug("Server side forward to: " + loginForm);
            }

            RequestDispatcher dispatcher = request.getRequestDispatcher(loginForm);

            dispatcher.forward(request, response);

            return;
        }
    } else {
        // redirect to login page. Use https if forceHttps true

        redirectUrl = buildRedirectUrlToLoginPage(request, response, authException);

    }

    redirectStrategy.sendRedirect(request, response, redirectUrl);
}

From source file:com.pearson.pdn.demos.chainoflearning.RegisterServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {

    String email = req.getParameter("email");
    if (email == null || !email.matches(EMAIL_PATTERN)) {
        res.sendRedirect(req.getContextPath() + "/register.jsp");
        return;/* www  .j a  va  2s.c o m*/
    }

    HttpSession session = req.getSession(true);

    // TODO - do this better. actually persist it...
    String verifyCode = Base64.encodeBase64String(String.valueOf(System.currentTimeMillis()).getBytes());
    session.setAttribute("auth", Base64.encodeBase64String((email + ":" + verifyCode).getBytes()));

    // TODO - actually send an email
    String linkParams = "?e=" + email + "&v=" + verifyCode;
    String emailContent = "Hello " + email + ",<br /><br /><a id=\"email-link\" href=\"./oauth2" + linkParams
            + "\">Link</a> your calendar with ChainOfLearning. <br/ > <br /> Thanks!";
    req.setAttribute("emailContent", emailContent);

    req.setAttribute("email", email);
    req.getRequestDispatcher("/activation.jsp").forward(req, res);
}

From source file:com.peso.Logout.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// w ww  .  j av a 2s  .c om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    boolean bError = false;
    String mensajeError = "";
    String nombre = "";
    String peso = "";
    //Errores

    if (request.getSession().getAttribute(Constantes.ATRIBUTO_NOMBRE) == null) {
        mensajeError = Constantes.MENSAJE_ERROR_NOMBRE_NO_EXISTE;
        bError = true;
    }

    if (!bError) {
        nombre = (String) request.getSession().getAttribute(Constantes.ATRIBUTO_NOMBRE);
        peso = (String) request.getSession().getAttribute(Constantes.ATRIBUTO_PESO);
        //Registrar el usuario
        request.getSession().setAttribute(Constantes.ATRIBUTO_NOMBRE, null);
        request.getSession().setAttribute(Constantes.ATRIBUTO_PESO, null);
        //Bienvenida
        request.setAttribute(Constantes.ATRIBUTO_NOMBRE, nombre);
        request.setAttribute(Constantes.ATRIBUTO_PESO, peso);
        request.getRequestDispatcher(Constantes.PAGINA_LOGOUT).forward(request, response);

    } else {
        request.setAttribute(Constantes.ATRIBUTO_ERROR, mensajeError);
        request.getRequestDispatcher(Constantes.PAGINA_ERROR).forward(request, response);
    }

}

From source file:edu.lternet.pasta.portal.HarvestReportServlet.java

/**
 * The doPost method of the servlet. <br>
 * /* www  . jav  a 2  s. c  om*/
 * This method is called when a form has its tag value method equals to post.
 * 
 * @param request
 *          the request send by the client to the server
 * @param response
 *          the response send by the server to the client
 * @throws ServletException
 *           if an error occurred
 * @throws IOException
 *           if an error occurred
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {
        HttpSession httpSession = request.getSession();
        String uid = (String) httpSession.getAttribute("uid");
        String warningMessage = null;

        if (uid == null) {
            warningMessage = "<p class=\"warning\">" + LOGIN_WARNING + "</p>";
            request.setAttribute("message", warningMessage);
        } else {
            String reportId = request.getParameter("reportId");
            if (reportId != null && reportId.length() > 0) {
                httpSession.setAttribute("harvestReportID", reportId);
            }
        }

        if (warningMessage == null || warningMessage.length() == 0) {
            response.sendRedirect("./harvestReport.jsp");
        } else {
            RequestDispatcher requestDispatcher = request.getRequestDispatcher("./harvestReport.jsp");
            requestDispatcher.forward(request, response);
        }
    } catch (Exception e) {
        handleDataPortalError(logger, e);
    }
}

From source file:br.com.gerenciapessoal.security.JsfLoginUrlAuthenticationEntryPoint.java

/**
 * Performs the redirect (or forward) to the login form URL.
 *
 * @param request/*from w  ww . j  a v a 2  s. c o m*/
 * @param response
 * @param authException
 * @throws java.io.IOException
 * @throws javax.servlet.ServletException
 */
@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {

    String redirectUrl = null;

    if (useForward) {

        if (forceHttps && "http".equals(request.getScheme())) {
            // First redirect the current request to HTTPS.
            // When that request is received, the forward to the login page will be used.
            redirectUrl = buildHttpsRedirectUrlForRequest(request);
        }

        if (redirectUrl == null) {
            String loginForm = determineUrlToUseForThisRequest(request, response, authException);

            if (logger.isDebugEnabled()) {
                logger.debug("Server side forward to: " + loginForm);
            }

            RequestDispatcher dispatcher = request.getRequestDispatcher(loginForm);

            dispatcher.forward(request, response);

            return;
        }
    } else {
        // redirect to login page. Use https if forceHttps true

        redirectUrl = buildRedirectUrlToLoginPage(request, response, authException);

    }

    redirectStrategy.sendRedirect(request, response, redirectUrl);
}

From source file:br.com.wavii.securyti.JsfLoginUrlAuthenticationEntryPoint.java

/**
 * Performs the redirect (or forward) to the login form URL.
 *//*  w  w  w. j  av  a2 s .com*/
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {

    String redirectUrl = null;

    if (useForward) {

        if (forceHttps && "http".equals(request.getScheme())) {
            // First redirect the current request to HTTPS.
            // When that request is received, the forward to the login page
            // will be used.
            redirectUrl = buildHttpsRedirectUrlForRequest(request);
        }

        if (redirectUrl == null) {
            String loginForm = determineUrlToUseForThisRequest(request, response, authException);

            if (logger.isDebugEnabled()) {
                logger.debug("Server side forward to: " + loginForm);
            }

            RequestDispatcher dispatcher = request.getRequestDispatcher(loginForm);

            dispatcher.forward(request, response);

            return;
        }
    } else {
        // redirect to login page. Use https if forceHttps true

        redirectUrl = buildRedirectUrlToLoginPage(request, response, authException);

    }

    redirectStrategy.sendRedirect(request, response, redirectUrl);
}

From source file:com.pkrete.locationservice.admin.interceptor.UserSessionInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    // Get current HTTP session
    HttpSession session = request.getSession();
    // Get User object from the session
    User user = (User) session.getAttribute("user");
    // Get remote user from the request
    String remoteUser = request.getRemoteUser();
    // If User is null and remote user is not null,
    // remote user must be added to the session
    if (user == null && remoteUser != null) {
        // Get User object by remote user from DB
        user = usersService.getUser(request.getRemoteUser());
        // If User is still null, stop the handler exceution chain
        if (user == null) {
            logger.warn(/*ww  w.  j  a  v a2 s  .c  o  m*/
                    "Unable to find User object matching the remote user \"{}\". Stop handler execution chain.",
                    remoteUser);
            // Logout the current user by forwarding to logout controller
            request.getRequestDispatcher("/logout.htm").forward(request, response);
            // Returning false stops the handler execution chain
            return false;
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Added User object to the session.");
        }
        // Add User object to the session
        session.setAttribute("user", user);
    } else if (user != null && remoteUser != null) {
        // Check that User and remote user are the same
        if (!user.getUsername().equals(remoteUser)) {
            logger.warn(
                    "Current user \"" + user.getUsername()
                            + "\" and remote user \"{}\" don't match. Stop handler execution chain.",
                    remoteUser);
            // Logout the current user by forwarding to logout controller
            request.getRequestDispatcher("/logout.htm").forward(request, response);
            // Stop handler execution chain if they don't match
            return false;
        }
    }
    // Continue handler execution chain
    return true;
}

From source file:br.com.sg.security.SgLoginUrlAuthenticationEntryPoint.java

/**
 * Performs the redirect (or forward) to the login form URL.
 *///from www .ja va  2  s.c  o m
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    String redirectUrl = null;

    if (useForward) {

        if (forceHttps && "http".equals(request.getScheme())) {
            // First redirect the current request to HTTPS.
            // When that request is received, the forward to the login page
            // will be used.
            redirectUrl = buildHttpsRedirectUrlForRequest(httpRequest);
        }

        if (redirectUrl == null) {
            String loginForm = determineUrlToUseForThisRequest(httpRequest, httpResponse, authException);

            if (logger.isDebugEnabled()) {
                logger.debug("Server side forward to: " + loginForm);
            }

            RequestDispatcher dispatcher = httpRequest.getRequestDispatcher(loginForm);

            dispatcher.forward(request, response);

            return;
        }
    } else {
        // redirect to login page. Use https if forceHttps true
        redirectUrl = buildRedirectUrlToLoginPage(httpRequest, httpResponse, authException);
    }

    redirectStrategy.sendRedirect(httpRequest, httpResponse, redirectUrl);
}