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.ns.cm.ProvisionServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println("Redirecting...");
    response.setContentType("text/html");
    response.setStatus(HttpServletResponse.SC_OK);
    response.sendRedirect(request.getContextPath());
}

From source file:com.lti.system.MyLogoutFilter.java

/**
 * Allow subclasses to modify the redirection message.
 *
 * @param request  the request/*from w  w  w. java  2 s  .com*/
 * @param response the response
 * @param url      the URL to redirect to
 *
 * @throws IOException in the event of any failure
 */
protected void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url)
        throws IOException {
    if (!url.startsWith("http://") && !url.startsWith("https://")) {
        url = request.getContextPath() + url;
    }

    response.sendRedirect(response.encodeRedirectURL(url));
}

From source file:com.sourcesense.alfresco.opensso.AlfrescoShareFilter.java

public void doFilter(ServletRequest sreq, ServletResponse sresp, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) sreq;
    HttpServletResponse res = (HttpServletResponse) sresp;
    HttpSession httpSession = req.getSession();

    SSOToken token = getOpenSSOClient().tokenFromRequest(req);

    if (isLogoutRequest(sreq)) {
        doLogout(httpSession, token);//from   w  ww . j  av a 2s  . c o  m
        res.sendRedirect(buildURLForRedirect(sreq));
    }

    try {
        RequestContext context = RequestUtil.getRequestContext(req);
        User user = context.getUser();
        if (user != null && !user.getId().equals(UserFactory.USER_GUEST)) {
            chain.doFilter(sreq, sresp);
            return;
        }
    } catch (RequestContextException e) {
        e.printStackTrace();
    }

    if (token == null) {
        res.sendRedirect(buildURLForRedirect(req));
    } else {
        UserFactory userFactory = FrameworkHelper.getUserFactory();
        String user = getOpenSSOClient().getPrincipal(token);
        boolean authenticated = userFactory.authenticate(req, user, token.getTokenID().toString());
        if (authenticated) {
            AuthenticationUtil.login(req, res, user);
        }
        chain.doFilter(sreq, sresp);
        return;
    }
}

From source file:wqm.web.server.controller.WQMCalibrationController.java

@ExceptionHandler(RedirectException.class)
public void handleException(HttpServletResponse response, RedirectException redirect) throws IOException {
    response.sendRedirect(redirect.getRedirectTo());
}

From source file:ar.com.zauber.commons.social.oauth.examples.services.ExampleAuthenticationSuccessHandler.java

/**
 * @see AuthenticationSuccessHandler#onAuthenticationSuccess(HttpServletRequest,
 *      HttpServletResponse, Authentication)
 *//*  w  w w .j  ava 2s.  co  m*/
@Override
public final void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response,
        final Authentication authentication) throws IOException, ServletException {

    ExampleUserDetails userDetails = (ExampleUserDetails) authentication.getPrincipal();

    if (userDetails.getUsername() == null) {
        // logged in with twitter, but no username for this application
        response.sendRedirect("/api/welcome/");
    } else {
        response.sendRedirect("/api/welcome/");
    }
}

From source file:org.iti.agrimarket.view.UpdateOfferController.java

/**
 * @Author Amr delete one offer from the Fixed offers table
 * @param offerid its the id of the offer
 * @return json opject {"success":1} if success
 * @return json opject {"success":0} if deletion error
 *
 *///from w ww  .  ja va2  s. co m
@RequestMapping(method = RequestMethod.GET, value = "/removeoffer.htm")
public String removeOffer(@RequestParam("offerid") Integer offerId, HttpServletRequest request,
        HttpServletResponse response, Model model) {

    System.out.println("in delete offer");

    offerService.deleteOffer(offerId);
    try {
        response.sendRedirect(request.getContextPath() + "/web/profile.htm");
    } catch (IOException ex) {
        java.util.logging.Logger.getLogger(UserController.class.getName()).log(Level.SEVERE, null, ex);
    }
    User oldUser = (User) request.getSession().getAttribute("user");
    if (oldUser != null) {
        User user = userService.getUserEager(oldUser.getId());
        request.getSession().setAttribute("user", user);
        model.addAttribute("user", user);
    }

    return "profile";

}

From source file:team.curise.controller.LoginController.java

@RequestMapping(value = "/logout", method = RequestMethod.POST)
public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
    System.out.println("logoutlogoutlogoutlogoutlogoutlogout");
    HttpSession session = request.getSession(true);
    session.removeAttribute("account");
    response.sendRedirect("login");
}

From source file:com.emc.plants.web.servlets.AccountServlet.java

/**
 * send redirect//w w w .jav a 2 s.c  o  m
 */
private void sendRedirect(HttpServletResponse resp, String page) throws ServletException, IOException {
    resp.sendRedirect(resp.encodeRedirectURL(page));
}

From source file:de.hybris.platform.acceleratorstorefrontcommons.security.StorefrontAuthenticationSuccessHandler.java

protected void invalidateSession(final HttpServletRequest request, final HttpServletResponse response)
        throws IOException {
    SecurityContextHolder.getContext().setAuthentication(null);
    request.getSession().invalidate();/*from  w  w w.  j a v  a 2s.  c o  m*/
    response.sendRedirect(request.getContextPath());
}

From source file:eventmanager.config.AuthenticationIntercepter.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
    User user = (User) request.getSession().getAttribute("usuario_logado");
    if (user == null) {
        String uri = request.getRequestURI();
        if (uri.endsWith("/login") || uri.endsWith("/loginForm")) {
            return true;
        }// ww  w.ja  v  a  2  s.  c  om
        response.sendRedirect("/EventsManagement2/loginForm");
        return false;

    } else {
        String uri = request.getRequestURI();
        if (uri.endsWith("/loginForm") || uri.endsWith("/EventsManagement2/login")) {
            response.sendRedirect("/EventsManagement2/User/menu");
            return false;
        }
        if (user.getType() == UserType.EMPRESA) {
            if (uri.endsWith("/config") || uri.contains("/User/delete") || uri.contains("/User/edit")) {
                response.sendRedirect("/EventsManagement2/User/menu");
                return false;
            }
        } else if (user.getType() == UserType.PARTICIPANTE) {
            if (uri.endsWith("/config") || uri.contains("/User/delete") || uri.contains("/User/edit")
                    || uri.contains("/Event/delete") || uri.contains("/Event/edit")) {
                response.sendRedirect("/EventsManagement2/User/menu");
                return false;
            }
        }
        return true;
    }
}