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:br.vschettino.forum.controller.SiteController.java

@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody//from  www  . ja v  a2s  .  c  om
public ModelAndView login(HttpServletRequest request, HttpServletResponse response,
        @RequestParam("usuario") String usuario, @RequestParam("senha") String senha) {
    Usuario visitante = usuarioDAO.authenticateUsuario(usuario, senha);
    try {
        if (visitante == null) {
            response.sendRedirect(request.getContextPath() + "/web/login?error=true");
            return null;
        }
        request.getSession().setAttribute("usuario", visitante);
        response.sendRedirect(request.getContextPath() + "/web/site/");
    } catch (IOException ex) {
        Logger.getLogger(SiteController.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:bigbluej.Client.java

public void joinMeeting(ServletResponse servletResponse, JoinCommand joinCommand) {
    try {// w w w  .  j a v a 2s  .  co  m
        Validate.notNull(joinCommand);
        String query = toQuery(ReflectionUtils.getFieldsAndValuesInSortedMap(joinCommand));
        String checksum = Checksum.create("join", query, sharedSecret);
        if (servletResponse instanceof HttpServletResponse) {
            String redirectUrl = url + "/join?" + query + "&checksum=" + checksum;
            System.out.println("redirect> " + redirectUrl);
            HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
            httpServletResponse.sendRedirect(redirectUrl);
            httpServletResponse.setStatus(200);
        }
    } catch (Exception e) {
        throw new ClientException(e);
    }
}

From source file:com.museum_web.controller.ChallengeController.java

@RequestMapping("actions/saveChallenge")
public void add(Challenge challenge, HttpServletResponse response) throws Exception {

    c.setDescription(challenge.getDescription());
    //            if(c.getChallengeId()<0)
    //                c.setChallengeId(null);
    cs.createChallenge(c);//from w  w w  .jav  a2  s  .c o m
    response.sendRedirect("../challengeCreate?id=" + c.getChallengeId());

}

From source file:com.wadpam.ricotta.web.IndexController.java

@RequestMapping(value = "/logout.html", method = RequestMethod.GET)
public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
    request.getSession().invalidate();//  w  w w  .ja  va2  s. c  om
    String logoutUrl = UserServiceFactory.getUserService().createLogoutURL("/classic/loggedout.html");
    response.sendRedirect(logoutUrl);
}

From source file:de.punyco.thirtytwosquare.auth.GoogleAppEngineAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {

    String loginURL = userService.createLoginURL(request.getRequestURI());

    if (LOG.isDebugEnabled()) {
        LOG.debug("Redirecting to login URL '{}'", loginURL);
    }//  ww  w  .  j ava 2  s. c o  m

    response.sendRedirect(loginURL);
}

From source file:org.terasoluna.gfw.functionaltest.app.redirect.WhiteListRedirectStrategy.java

public void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url)
        throws IOException {
    if (checkWhiteList(url)) {
        String redirectUrl = response.encodeRedirectURL(url);

        if (logger.isDebugEnabled()) {
            logger.debug("Redirecting to '" + redirectUrl + "'");
        }/*from  w w w  .  j av a2 s .com*/

        response.sendRedirect(redirectUrl);

    } else {
        response.sendError(HttpServletResponse.SC_FORBIDDEN, url);
    }
}

From source file:com.googlecode.commonspringaspects.servlets.PerformanceHttpRequestHandler.java

public void handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    if (!enabled) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;/*from   ww w . ja v a  2  s  . com*/
    }

    if (request.getMethod().equals("POST")) {

        MonitorFactory.reset();
        response.sendRedirect(request.getRequestURI());

    } else {

        response.setContentType("text/html");
        PrintWriter writer = response.getWriter();
        writer.print("<html>");
        writer.print("<body><form action='' method='post'> <input type='submit' value='Reset JAMon'> </form>");
        writer.print(MonitorFactory.getRootMonitor().getReport(3, "desc"));
        writer.print("</body></html>");

    }
}

From source file:org.chos.transaction.passport.controller.PassportController.java

@RequestMapping(value = "/user/logout")
@ResponseBody//from   w  ww .ja v a 2 s  . c  o  m
public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Session session = httpContextSessionManager.getSession(request);
    if (session != null) {
        httpContextSessionManager.close(response);
    }
    response.sendRedirect("../login.shtml");
}

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

@RequestMapping(value = "/home", method = RequestMethod.GET)
public String login(Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session)
        throws Exception {
    logger.debug("Received request to show home page");

    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. java2  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;
            }
        }

    }

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

From source file:th.co.geniustree.osgi.prototype.authen.security.DefaultLogoutSuccessHandler.java

private void invalidSessionAndRedirect(HttpSession session, HttpServletResponse response, String redirectUrl)
        throws IOException {
    try {/*from w  ww .  j  a va2  s . com*/
        session.invalidate();
    } catch (Exception ex) {
        //swallow exception
        ex.printStackTrace();
    } finally {
        response.setStatus(HttpServletResponse.SC_OK);
        response.sendRedirect(redirectUrl);
    }
}