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.jhkt.playgroundArena.examples.generic.interceptors.OpenTimeInterceptor.java

public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {

    Calendar cal = Calendar.getInstance();
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    if (openingTime <= hour && hour < closingTime) {
        return true;
    } else {/*from  w w  w.j  a  va  2  s .  co m*/
        response.sendRedirect("http://localhost/closed.html");
        return false;
    }
}

From source file:org.chos.transaction.controller.MerchantManagerController.java

@RequestMapping(value = "/merchant/{id}/details")
public String merchantDetails(@PathVariable int id, HttpServletRequest request, HttpServletResponse response,
        Model model) throws IOException {
    Session session = httpContextSessionManager.getSession(request);
    if (session == null) {
        response.sendRedirect("login.shtml");
    }/*from w  w  w  . jav  a  2  s  .  c  o  m*/
    Merchant merchant = userService.getMerchantByUserId(session.getUserId());
    if (merchant == null) {
        response.sendRedirect("/continue.shtml");
    }

    List<DocumentPart> document = documentService.getDocument(merchant.getId(), 3);
    model.addAttribute("document", document);
    return "business/tmpl-merchant-details";
}

From source file:org.chos.transaction.controller.MerchantManagerController.java

@RequestMapping(value = "/merchant0/{id}/details")
public String merchant00(@PathVariable int id, HttpServletRequest request, HttpServletResponse response,
        Model model) throws IOException {
    Session session = httpContextSessionManager.getSession(request);
    if (session == null) {
        response.sendRedirect("login.shtml");
    }//ww w .  j  a  va 2s .co m
    Merchant merchant = userService.getMerchantByUserId(session.getUserId());
    if (merchant == null) {
        response.sendRedirect("/continue.shtml");
    }

    List<DocumentPart> document = documentService.getDocument(merchant.getId(), 3);
    List<Category> categories = itemService.getCategories(session.getUserId());
    model.addAttribute("merchant", merchant);
    model.addAttribute("categories", categories);
    model.addAttribute("document", document);
    return "business/merchant";
}

From source file:org.terasoluna.gfw.security.web.redirect.RedirectAuthenticationHandlerTest.java

@Test
public void testOnAuthenticationSuccess_SetCustomeRedirectToRedirectStrategy() throws Exception {
    RedirectAuthenticationHandler redireHandler = new RedirectAuthenticationHandler();
    redireHandler.setRedirectToRedirectStrategy(new RedirectStrategy() {
        @Override//www. j a va2 s  .c o m
        public void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url)
                throws IOException {
            response.sendRedirect("http://google.com");
        }
    });
    redireHandler.afterPropertiesSet();

    // set Blank URI
    String redirectURI = "/foo/bar";
    request.setParameter("redirectTo", redirectURI);

    // expected data
    String expectedRedirectURL = "http://google.com";

    // run
    redireHandler.onAuthenticationSuccess(request, response, auth);

    // assert
    assertThat(response.getRedirectedUrl(), is(expectedRedirectURL));
}

From source file:cs472.w1d5.servlet.Welcome.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from   w w  w  . j av  a2 s . c om*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession session = request.getSession();
    String user = (String) session.getAttribute("user");
    if (user == null) {
        response.sendRedirect("login.html");
        return;
    }

    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet Welcome</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Welcome " + escapeHtml(user) + "</h1>");
        out.println("<p><a href='Logout'>logout</p>");
        out.println("</body>");
        out.println("</html>");
    }
}

From source file:com.hp.autonomy.frontend.find.core.web.FindController.java

@RequestMapping("/")
public void index(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    final String contextPath = request.getContextPath();

    if (LoginTypes.DEFAULT.equals(authenticationConfigService.getConfig().getAuthentication().getMethod())) {
        response.sendRedirect(contextPath + DEFAULT_LOGIN_PAGE);
    } else {//w  ww . j a va  2s  .c o m
        response.sendRedirect(contextPath + APP_PATH);
    }
}

From source file:cn.vlabs.umt.ui.actions.ActivationSecurityAction.java

public ActionForward activeSecurityEmail(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    ActivationForm data = (ActivationForm) form;
    if (!getTokenService().isValid(data.getTokenid(), data.getRandom(),
            Token.OPERATION_ACTIVATION_SECURITY_EMAIL)) {
        response.sendRedirect(ShowPageAction.getMessageUrl(request, "active.security.email.fail"));
        return null;
    }/*w  w w. java  2  s.  c o  m*/
    Token token = getTokenService().getTokenById(data.getTokenid());

    User user = getUserService().getUserByUid(token.getUid());
    AbstractDoActivation doAction = new DoActivationServiceForSecurity(request, response, token, user, data);
    return doAction.doActivation();

}

From source file:org.chos.transaction.controller.MerchantManagerController.java

@RequestMapping(value = "/merchant")
public String merchant(HttpServletRequest request, HttpServletResponse response, Model model)
        throws IOException {
    Session session = httpContextSessionManager.getSession(request);
    if (session == null) {
        response.sendRedirect("login.shtml");
        return null;
    }//  w  w w  .j  av a 2 s .c  om
    Merchant merchant = userService.getMerchantByUserId(session.getUserId());
    if (merchant == null) {
        response.sendRedirect("/continue.shtml");
        return null;
    }

    List<DocumentPart> document = documentService.getDocument(merchant.getId(), 3);
    List<Category> categories = itemService.getCategories(session.getUserId());
    List<Product> products = productService.getByUserId(session.getUserId());
    model.addAttribute("merchant", merchant);
    model.addAttribute("document", document);
    model.addAttribute("categories", categories);
    model.addAttribute("products", products);
    return "business/merchant";
}

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

@RequestMapping(value = "/history", method = RequestMethod.GET)
public String showHistory(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.jav  a  2  s .c  o  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;
            }
        }

    }

    logger.debug("Received request to show command history");
    UserPref userPref = (UserPref) session.getAttribute("prefs");

    String histAction = request.getParameter("histAction");

    if (histAction != null) {
        logger.debug("histAction = " + histAction);
        // clear history
        session.setAttribute("history", new LinkedList());

        model.addAttribute("historyremoved", "Succesfully cleared history list");
    }

    LinkedList historyList = (LinkedList) session.getAttribute("history");

    int maxsize = userPref.getHistorySize();

    model.addAttribute("historyList", historyList.toArray());
    model.addAttribute("historysize", historyList.size());

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

From source file:com.palantir.stash.disapprove.servlet.StaticContentServlet.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

    final String user = authenticateUser(req, res);
    if (user == null) {
        // not logged in, redirect
        res.sendRedirect(lup.getLoginUri(getUri(req)).toASCIIString());
        return;//w  w w.  j  a  v a2  s. co  m
    }

    final String pathInfo = req.getPathInfo();
    OutputStream os = null;
    try {
        // The class loader that found this class will also find the static resources
        ClassLoader cl = this.getClass().getClassLoader();
        InputStream is = cl.getResourceAsStream(PREFIX + pathInfo);
        if (is == null) {
            res.sendError(404, "File " + pathInfo + " could not be found");
            return;
        }
        os = res.getOutputStream();
        //res.setContentType("text/html;charset=UTF-8");
        String contentType = URLConnection.guessContentTypeFromStream(is);
        if (contentType == null) {
            contentType = URLConnection.guessContentTypeFromName(pathInfo);
        }
        if (contentType == null) {
            contentType = "application/binary";
        }
        log.debug("Serving file " + pathInfo + " with content type " + contentType);
        res.setContentType(contentType);
        IOUtils.copy(is, os);
        /*
        byte[] buffer = new byte[4096];
        int bytesRead = 0;
        while ((bytesRead = bis.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
        }
        */
    } finally {
        if (os != null) {
            os.close();
        }
    }
}