Example usage for javax.servlet.http HttpServletResponse sendRedirect

List of usage examples for javax.servlet.http HttpServletResponse sendRedirect

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse sendRedirect.

Prototype

public void sendRedirect(String location) throws IOException;

Source Link

Document

Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer.

Usage

From source file:com.google.zxing.web.DecodeServlet.java

private static void processStream(InputStream is, ServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    BufferedImage image;/*w ww.j a  v  a2  s . co  m*/
    try {
        image = ImageIO.read(is);
    } catch (IOException | CMMException | IllegalArgumentException ioe) {
        log.info(ioe.toString());
        // Have seen these in some logs
        response.sendRedirect("badimage.jspx");
        return;
    }
    if (image == null) {
        response.sendRedirect("badimage.jspx");
        return;
    }
    if (image.getHeight() <= 1 || image.getWidth() <= 1 || image.getHeight() * image.getWidth() > MAX_PIXELS) {
        log.info("Dimensions out of bounds: " + image.getWidth() + 'x' + image.getHeight());
        response.sendRedirect("badimage.jspx");
        return;
    }

    processImage(image, request, response);
}

From source file:fll.web.DoLogin.java

/**
 * Does the work of login. Exists as a separate method so that it can be
 * called from {@link fll.web.admin.CreateUser}
 */// w w w.  ja va2s.  c o m
public static void doLogin(final HttpServletRequest request, final HttpServletResponse response,
        final ServletContext application, final HttpSession session) throws IOException, ServletException {
    final DataSource datasource = ApplicationAttributes.getDataSource(application);
    Connection connection = null;
    try {
        connection = datasource.getConnection();

        // check for authentication table
        if (Queries.isAuthenticationEmpty(connection)) {
            LOGGER.warn("No authentication information in the database");
            session.setAttribute(SessionAttributes.MESSAGE,
                    "<p class='error'>No authentication information in the database - see administrator</p>");
            response.sendRedirect(response.encodeRedirectURL("login.jsp"));
            return;
        }

        // compute hash
        final String user = request.getParameter("user");
        final String pass = request.getParameter("pass");
        if (null == user || user.isEmpty() || null == pass || pass.isEmpty()) {
            LOGGER.warn("Form fields missing");
            session.setAttribute(SessionAttributes.MESSAGE,
                    "<p class='error'>You must fill out all fields in the form.</p>");
            response.sendRedirect(response.encodeRedirectURL("login.jsp"));
            return;
        }
        final String hashedPass = DigestUtils.md5Hex(pass);

        // compare login information
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Checking user: " + user + " hashedPass: " + hashedPass);
        }
        final Map<String, String> authInfo = Queries.getAuthInfo(connection);
        for (final Map.Entry<String, String> entry : authInfo.entrySet()) {
            if (user.equals(entry.getKey()) && hashedPass.equals(entry.getValue())) {
                // clear out old login cookies first
                CookieUtils.clearLoginCookies(application, request, response);

                final String magicKey = String.valueOf(System.currentTimeMillis());
                Queries.addValidLogin(connection, user, magicKey);
                CookieUtils.setLoginCookie(response, magicKey);

                String redirect = SessionAttributes.getRedirectURL(session);
                if (null == redirect) {
                    redirect = "index.jsp";
                }
                response.sendRedirect(response.encodeRedirectURL(redirect));
                return;
            } else {
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Didn't match user: " + entry.getKey() + " pass: " + entry.getValue());
                }
            }
        }

        LOGGER.warn("Incorrect login credentials user: " + user);
        session.setAttribute(SessionAttributes.MESSAGE,
                "<p class='error'>Incorrect login information provided</p>");
        response.sendRedirect(response.encodeRedirectURL("login.jsp"));
        return;
    } catch (final SQLException e) {
        throw new RuntimeException(e);
    } finally {
        SQLFunctions.close(connection);
    }
}

From source file:com.edgenius.wiki.util.WikiUtil.java

/**
 * @param model/*from   ww  w .  j  av  a 2 s. c o m*/
 * @return 
 */
public static boolean captchaValid(CaptchaServiceProxy captchaService, CaptchaCodeModel model) {
    if (model != null && model.reqireCaptcha) {
        HttpServletRequest request = WebUtil.getRequest();
        HttpServletResponse response = WebUtil.getResponse();
        String id = request.getSession().getId();
        boolean valid = captchaService.validateReponseForId(id, model.captchaCode);
        if (!valid) {
            try {
                //here does not put webcontext - it is fine as GwtSpringController only do endWith() check.
                response.sendRedirect(WikiConstants.URL_CAPTCHA_VERIFIED_ERROR);
            } catch (IOException e) {
                log.error("Redir failed:" + WikiConstants.URL_CAPTCHA_VERIFIED_ERROR, e);
            }
            return false;
        }
    }
    return true;
}

From source file:com.redhat.rhn.frontend.action.LoginHelper.java

/** static method shared by LoginAction and LoginSetupAction
 * @param request actual request/*from  ww w  .j  a v a  2 s.co m*/
 * @param response actual reponse
 * @param user logged in user
 * @return returns true, if redirect
 */
public static boolean successfulLogin(HttpServletRequest request, HttpServletResponse response, User user) {
    // set last logged in
    user.setLastLoggedIn(new Date());
    UserManager.storeUser(user);
    // update session with actual user
    PxtSessionDelegateFactory.getInstance().newPxtSessionDelegate().updateWebUserId(request, response,
            user.getId());

    LoginHelper.publishUpdateErrataCacheEvent(user.getOrg());
    // redirect, if url_bounce set
    String urlBounce = request.getParameter("url_bounce");
    String reqMethod = request.getParameter("request_method");

    urlBounce = LoginAction.updateUrlBounce(urlBounce, reqMethod);
    try {
        if (urlBounce != null) {
            log.info("redirect: " + urlBounce);
            response.sendRedirect(urlBounce);
            return true;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:io.fabric8.che.starter.controller.SwaggerController.java

@GetMapping
public void redirectToSwagger(HttpServletResponse response) throws IOException {
    response.sendRedirect("/swagger-ui.html");
}

From source file:dijalmasilva.controllers.Session.java

@RequestMapping("/")
public void index(HttpServletResponse resp) throws IOException {
    resp.sendRedirect("/home");
}

From source file:fi.helsinki.opintoni.web.controller.RootController.java

@RequestMapping(value = "/")
public void redirect(HttpServletResponse response) throws IOException {
    response.sendRedirect(appConfiguration.get("appRelativeUrl"));
}

From source file:videoquotes.controller.VideoDLSvc.java

@RequestMapping(value = "/video", method = RequestMethod.GET)
public void findOne(@RequestParam String id, HttpServletResponse response) throws IOException {
    response.sendRedirect(URLDecoder.decode(videoDLs.findOne(id).getUrl(), "UTF-8"));
}

From source file:edu.cornell.mannlib.vedit.forwarder.impl.UrlForwarder.java

public void doForward(HttpServletRequest request, HttpServletResponse response, EditProcessObject epo) {
    try {//  w  w w .  j  a va2  s  . c o m
        response.sendRedirect(response.encodeRedirectURL(theUrl));
    } catch (IOException ioe) {
        log.error("doForward() could not send redirect.");
    }
}

From source file:furkan.app.tictactoewebsocket.TicTacToeServlet.java

private void list(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/tictactoe"));
}