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:de.u808.simpleinquest.web.download.DownloadController.java

private ModelAndView handleError(HttpServletResponse response, DownloadCommand downloadCommand, String errorKey,
        String errorMessage) throws ParseException, IOException {
    SearchResult searchResult = this.searchManager.search(downloadCommand.getSearchString());
    searchResult.setPageIndex(downloadCommand.getPageIndex());
    searchResult.addErrorMessage(errorKey, errorMessage);
    response.sendRedirect("../search.htm?searchString=" + downloadCommand.getSearchString() + "&pageIndex="
            + downloadCommand.getPageIndex());
    return null;//from  w  w  w . j av  a2s. co m
}

From source file:com.buzzinate.buzzads.sso.CasAuthenticationEntryPoint.java

public final void commence(final HttpServletRequest servletRequest, final HttpServletResponse response,
        final AuthenticationException authenticationException) throws IOException, ServletException {

    final String urlEncodedService = createServiceUrl(servletRequest, response);
    final String redirectUrl = createRedirectUrl(urlEncodedService);

    preCommence(servletRequest, response);

    response.sendRedirect(redirectUrl);
}

From source file:org.jtalks.poulpe.web.AuthenticationCleaningAccessDeniedExceptionHandler.java

@Override
public void handle(HttpServletRequest request, HttpServletResponse response,
        AccessDeniedException accessDeniedException) throws IOException, ServletException {

    String errorPage;//w  w w . j av a 2 s .c  o m
    if (alternativeRoutes.containsKey(request.getServletPath())) {
        errorPage = alternativeRoutes.get(request.getServletPath());
    } else {
        SecurityContextHolder.getContext().setAuthentication(null);
        errorPage = defaultErrorPage;
    }
    response.sendRedirect(request.getContextPath() + errorPage);
}

From source file:org.chos.transaction.order.controller.OrderController.java

@RequestMapping(value = "cart")
public void cart(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Session session = httpContextSessionManager.getSession(request);
    if (session == null) {
        response.sendRedirect("login.shtml");
    }//from   w w  w .ja v  a 2  s  .c  o  m
    String itemId = request.getParameter("item");
    if (StringUtils.isBlank(itemId)) {
        response.sendRedirect("item/error.shtml");
    }
    Item item = itemService.getItem(Integer.parseInt(itemId));
    if (item == null) {
        response.sendRedirect("item/error.shtml");
    }
    OrderSheet order = new OrderSheet();
    String no = UUID.randomUUID().toString();
    no = no.replaceAll("-", "");
    order.setAmount(item.getAmount());
    order.setUt(session.getToken());
    order.setItemId(item.getId());
    order.setItemType(0);
    order.setQuantity(1);
    order.setCreation(new Date());

    orderSheetService.cart(order);
    response.sendRedirect("order-sheet.shtml");
}

From source file:pivotal.au.se.gemfirexdweb.controller.CreateTriggerController.java

@RequestMapping(value = "/createtrigger", method = RequestMethod.POST)
public String createTriggerAction(@ModelAttribute("triggerAttribute") NewTrigger triggerAttribute, Model model,
        HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {//w w w .  j  a  v a2 s  .  c  om
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to action an event for create Trigger");

    TableDAO tableDAO = GemFireXDWebDAOFactory.getTableDAO();

    List<Table> tables = tableDAO.retrieveTableList((String) session.getAttribute("schema"), null,
            (String) session.getAttribute("user_key"), "tables");

    model.addAttribute("tables", tables);

    String schema = triggerAttribute.getSchemaName().trim();

    if (schema.length() == 0) {
        schema = (String) session.getAttribute("schema");
    }

    logger.debug("New Trigger schema name = " + schema);
    logger.debug("New Trigger name = " + triggerAttribute.getTriggerName());

    // perform some action here with what we have
    String submit = request.getParameter("pSubmit");

    if (submit != null) {
        // build create HDFS Store SQL
        StringBuffer createTrigger = new StringBuffer();

        createTrigger.append("CREATE TRIGGER " + schema + "." + triggerAttribute.getTriggerName() + " \n");
        createTrigger.append(triggerAttribute.getBeforeOrAfter() + " \n");
        createTrigger.append(triggerAttribute.getType() + " \n");

        if (!checkIfParameterEmpty(request, "columnList")) {
            createTrigger.append("OF " + triggerAttribute.getColumnList() + " \n");
        }

        createTrigger.append("ON " + triggerAttribute.getTableName() + " \n");

        if (!checkIfParameterEmpty(request, "referencingOldClause")) {
            createTrigger.append("REFERENCING OLD AS " + triggerAttribute.getReferencingOldClause() + " \n");
        }

        if (!checkIfParameterEmpty(request, "referencingNewClause")) {
            createTrigger.append("REFERENCING NEW AS " + triggerAttribute.getReferencingNewClause() + " \n");
        }

        createTrigger.append(triggerAttribute.getForEachRow() + " \n");

        if (!checkIfParameterEmpty(request, "triggerDefinition")) {
            createTrigger.append(triggerAttribute.getTriggerDefinition() + " \n");
        }

        if (submit.equalsIgnoreCase("create")) {
            Result result = new Result();

            logger.debug("Creating Trigger as -> " + createTrigger.toString());

            result = GemFireXDWebDAOUtil.runCommand(createTrigger.toString(),
                    (String) session.getAttribute("user_key"));

            model.addAttribute("result", result);
            model.addAttribute("tableName", triggerAttribute.getTableName());

        } else if (submit.equalsIgnoreCase("Show SQL")) {
            logger.debug("Create Trigger SQL as follows as -> " + createTrigger.toString());
            model.addAttribute("sql", createTrigger.toString());
            model.addAttribute("tableName", triggerAttribute.getTableName());
        } else if (submit.equalsIgnoreCase("Save to File")) {
            response.setContentType(SAVE_CONTENT_TYPE);
            response.setHeader("Content-Disposition",
                    "attachment; filename=" + String.format(FILENAME, triggerAttribute.getTriggerName()));

            ServletOutputStream out = response.getOutputStream();
            out.println(createTrigger.toString());
            out.close();
            return null;
        }

    }

    // This will resolve to /WEB-INF/jsp/create-trigger.jsp
    return "create-trigger";
}

From source file:fr.scc.elo.controller.PlayerController.java

@GET
@Produces({ MediaType.TEXT_HTML })
@Path("/delete/{name}")
public void deletePlayer(@Context HttpServletRequest http, @Context HttpServletResponse redirect,
        @PathParam("name") String name) throws IOException {

    if (connectionService.acceptIPDelete(http.getRemoteAddr())) {
        eloService.deletePlayer(Player.builder().name(name).build());
    }/*from  w ww.  j a v a 2s  . c  om*/
    redirect.sendRedirect("/rest/v1/player/showall/html");
}

From source file:com.alliander.osgp.shared.security.MellonTokenProcessingFilter.java

private void logoutMellon(final HttpServletResponse httpResponse, final String username)
        throws ServletException, IOException {

    try {/*from w w w . j ava 2 s .  c o  m*/
        this.authenticationManager.logout(username);
    } catch (final KeycloakClientException e) {
        LOGGER.error("Error logging user '{}' out with the Keycloak API.", username, e);
    }

    httpResponse.sendRedirect(this.logoutUrl);
}

From source file:controllers.UrlController.java

@RequestMapping(value = "", method = RequestMethod.GET)
public void index1(HttpServletRequest request, HttpServletResponse response) throws IOException {

    response.sendRedirect("index");
}

From source file:edu.cornell.mannlib.vitro.webapp.i18n.selection.LocaleSelectionController.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String referrer = req.getHeader("referer");

    String selectedLocale = req.getParameter(PARAMETER_SELECTION);

    try {/*  w ww .  j a v a 2 s .  c  o  m*/
        processSelectedLocale(req, selectedLocale);
    } catch (Exception e) {
        log.error("Failed to process the user's Locale selection", e);
    }

    if (StringUtils.isEmpty(referrer)) {
        resp.sendRedirect(UrlBuilder.getHomeUrl());
    } else {
        resp.sendRedirect(referrer);
    }
}

From source file:br.vschettino.forum.controller.DiscussaoController.java

@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody/*  w ww . jav  a 2  s  . c  o m*/
public String create(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Discussao d = new Discussao();
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    d.setTitulo(request.getParameter("titulo"));
    d.setConteudo(request.getParameter("conteudo"));
    d.setAutor((Usuario) request.getSession().getAttribute("usuario"));
    d.setData_criacao(format.format(new Date()));
    discussaoDAO.save(d);
    response.sendRedirect(request.getContextPath() + "/web/discussao/");
    return null;
}