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:elw.web.AdminController.java

@RequestMapping(value = "logout", method = RequestMethod.GET)
public ModelAndView do_logout(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    req.getSession(true).invalidate();//w  w  w.  j a v  a  2 s .c  o  m
    resp.sendRedirect("index");
    return null;
}

From source file:com.netsteadfast.greenstep.base.filter.WebLoginCheckFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    String redirectUrl = filterConfig.getInitParameter("redirectUrl");
    if (StringUtils.isBlank(redirectUrl)) {
        redirectUrl = "/pages/system/login_again.jsp";
    }//from w  w w.j ava  2 s.co m
    Object accountObj = httpRequest.getSession().getAttribute(Constants.SESS_ACCOUNT);
    if (accountObj == null || !(accountObj instanceof AccountObj)) {
        httpResponse.sendRedirect(request.getServletContext().getContextPath() + redirectUrl);
        return;
    }
    if (!this.isLogin(httpRequest, (AccountObj) accountObj)) {
        return;
    }
    chain.doFilter(request, response);
}

From source file:gwtupload.server.gae.BlobstoreUploadAction.java

protected void redirect(HttpServletResponse response, String params) throws IOException {
    String url = servletPath + "?" + PARAM_REDIRECT + "=true"
            + (params != null ? "&" + params.replaceAll("[\n\r]+", " ") : "");
    logger.info("BLOB-STORE-SERVLET: redirecting to -> : " + url);
    response.sendRedirect(url);
}

From source file:it.smartcommunitylab.carpooling.controllers.UserAuthController.java

@RequestMapping("/userlogin/{authority}")
public void loginAuthority(@PathVariable String authority, @RequestParam(required = false) String token,
        HttpServletResponse response) throws IOException {
    String url = service.generateAuthorizationURIForCodeFlow(env.getProperty("ext.redirect"), "/" + authority,
            null, null);// w ww  . j a  v  a  2 s .  co  m
    if (token != null) {
        url += "&token=" + token;
    }
    response.sendRedirect(url);
}

From source file:com.mobogenie.framework.spring.CookieLocaleFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    if (isCookieChangePage(request)) {
        String locale = WebUtils.findParameterValue(request, "request_locale");
        if (StringUtils.isBlank(locale)
                || (!locale.equalsIgnoreCase("en_US") && !locale.equalsIgnoreCase("zh_CN"))) {
            locale = "zh_CN";
        }// w  w  w.  j a v  a2  s .  c  om
        localeResolver.addCookie(response, locale);
        response.sendRedirect(redirectUrl);
        return;
    }
    chain.doFilter(request, response);

}

From source file:ch.newscron.newscronjsp.ShortUrlCreator.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*w  w  w.ja  v a  2  s  .com*/
        String customerId = request.getParameter("customerId");
        String rew1 = request.getParameter("rew1");
        String rew2 = request.getParameter("rew2");
        String val = request.getParameter("val");

        String urlEncoded = encodeUrl(customerId, rew1, rew2, val);
        if (urlEncoded == null) {
            response.sendRedirect(domain);
        } else {
            insertToDatabase(Long.parseLong(customerId), domain + "referral/" + urlEncoded);
            String redirectURL = domain + "userShortUrlStats?customerId=" + customerId;
            response.sendRedirect(redirectURL);
        }

    } catch (Exception ex) {
        Logger.getLogger(ShortUrlCreator.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.microsoft.azure.oidc.filter.helper.impl.SimpleAuthenticationHelper.java

private void doRedirectRequestAction(final HttpServletRequest httpRequest,
        final HttpServletResponse httpResponse, final State state) throws IOException {
    httpResponse.sendRedirect(getStateRedirectURL(httpRequest, state));
}

From source file:com.alfaariss.oa.helper.stylesheet.handler.RedirectHandler.java

/**
 * @see com.alfaariss.oa.helper.stylesheet.handler.AbstractStyleSheetHandler#process(com.alfaariss.oa.api.session.ISession, javax.servlet.http.HttpServletResponse, boolean)
 *//*w  w w  .j av  a2 s.c o  m*/
public void process(ISession session, HttpServletResponse response, boolean isWireless)
        throws StyleSheetException {
    try {
        String sStyleSheet = super.resolveStyleSheetLocation(session, isWireless);
        if (sStyleSheet != null) {
            if (response.isCommitted()) {
                _logger.error("Response already committed");
                throw new StyleSheetException(SystemErrors.ERROR_RESOURCE_CONNECT);
            }

            response.sendRedirect(sStyleSheet);
        }
    } catch (StyleSheetException e) {
        throw e;
    } catch (Exception e) {
        _logger.fatal("Unable to process request", e);
        throw new StyleSheetException(SystemErrors.ERROR_INTERNAL);
    }
}

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

@RequestMapping(value = "/gatewaysenders", method = RequestMethod.POST)
public String performGatewaySendersAction(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 {/*from   w  w  w . ja  v a2 s .co  m*/
        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;
            }
        }

    }

    int startAtIndex = 0, endAtIndex = 0;
    Result result = new Result();
    List<GatewaySender> gatewaysenders = null;

    logger.debug("Received request to perform an action on the gateway senders");

    GatewaySenderDAO gsDAO = GemFireXDWebDAOFactory.getGatewaySenderDAO();

    if (request.getParameter("search") != null) {
        gatewaysenders = gsDAO.retrieveGatewaySenderList((String) session.getAttribute("schema"),
                (String) request.getParameter("search"), (String) session.getAttribute("user_key"));

        model.addAttribute("search", (String) request.getParameter("search"));
    } else {
        String[] tableList = request.getParameterValues("selected_gatewaysenders[]");
        String commandStr = request.getParameter("submit_mult");

        logger.debug("tableList = " + Arrays.toString(tableList));
        logger.debug("command = " + commandStr);

        // start actions now if tableList is not null

        if (tableList != null) {
            List al = new ArrayList<Result>();
            for (String senderId : tableList) {
                result = null;
                result = gsDAO.simplegatewaySenderCommand(senderId, commandStr,
                        (String) session.getAttribute("user_key"));
                al.add(result);
            }

            model.addAttribute("arrayresult", al);
        }

        gatewaysenders = gsDAO.retrieveGatewaySenderList((String) session.getAttribute("schema"), null,
                (String) session.getAttribute("user_key"));
    }

    model.addAttribute("records", gatewaysenders.size());
    model.addAttribute("estimatedrecords", gatewaysenders.size());

    UserPref userPref = (UserPref) session.getAttribute("prefs");

    if (gatewaysenders.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("gatewaysenders", gatewaysenders);
    } else {
        if (request.getParameter("startAtIndex") != null) {
            startAtIndex = Integer.parseInt(request.getParameter("startAtIndex"));
        }

        if (request.getParameter("endAtIndex") != null) {
            endAtIndex = Integer.parseInt(request.getParameter("endAtIndex"));
            if (endAtIndex > gatewaysenders.size()) {
                endAtIndex = gatewaysenders.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();
        }

        List subList = gatewaysenders.subList(startAtIndex, endAtIndex);
        model.addAttribute("gatewaysenders", subList);
    }

    model.addAttribute("startAtIndex", startAtIndex);
    model.addAttribute("endAtIndex", endAtIndex);

    // This will resolve to /WEB-INF/jsp/gatewaysenders.jsp
    return "gatewaysenders";

}

From source file:com.orig.gls.web.category.Categoryw.java

public static void handleMaintainCategory(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession session = request.getSession(false);
    session.setAttribute("catadded", false);
    session.setAttribute("catexists", false);
    if ((String) session.getAttribute("uname") != null) {
        String function = request.getParameter("function");
        String categorytype = request.getParameter("categorytype");
        String categorycode = request.getParameter("categorycode");
        String categoryvalue = request.getParameter("categoryvalue");
        switch (function) {
        case "ADD":
            if (!Category.categoryExists(categorycode, categorytype)) {
                Category.addCategories(Bank.getBankId(), categorycode, categorytype, categoryvalue, new Date(),
                        (String) session.getAttribute("uname"), new Date(),
                        (String) session.getAttribute("uname"));
                session.setAttribute("catadded", true);
                session.setAttribute("content_page", "categories/mCategories_a.jsp");
            } else {
                session.setAttribute("catexists", true);
                session.setAttribute("content_page", "categories/mCategories_b.jsp");
            }/*from w  ww .  j a v a2s . c o  m*/
            break;
        }
    } else {
        session.setAttribute("content_page", "sessionexp.jsp");
    }
    response.sendRedirect("index.jsp");
}