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.basicservice.controller.UserController.java

@RequestMapping(value = "/registrationConfirmation", method = RequestMethod.GET)
public ResponseEntity<String> confirmEmail(HttpServletRequest request,
        @RequestParam(value = "key") UUIDValidatedString key, HttpServletResponse response) {
    String validatdKey = Utils.getValueFromValidatedString(key);
    if (validatdKey != null) {
        String userId = confirmationEmailService.confirmEmail(key);
        if (userId != null) {
            User user = userService.get(userId);
            user.setEmailConfirmed(true);
            userService.save(user);//from  w w w . ja  v a2 s  .  c  o  m
        }
    }
    String uri = Utils.getBasicPath(request);
    try {
        response.sendRedirect(response.encodeRedirectURL(uri));
    } catch (IOException e) {
    }
    return new ResponseEntity<String>(HttpStatus.OK);
}

From source file:com.naver.timetable.interceptor.LoginInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    HttpSession session = request.getSession();
    //user  ?? ? ?
    User user = (User) session.getAttribute("user");
    if (session.getAttribute("user") == null) {
        // Login? 
        if (request.getRequestURI().equals("/login/login"))
            return true;
        if (request.getRequestURI().equals("/login/join"))
            return true;
        session.setAttribute("targetPage", request.getRequestURI());
        response.sendRedirect("/login/login");
        return false;
    }/* ww  w  .j  a  va 2  s  .c om*/
    //?? ?  ? login ? join?   .
    if (request.getRequestURI().equals("/login/login") || request.getRequestURI().equals("/login/join")) {
        response.sendRedirect("/lecture/index");
        return false;
    }
    //      Method method = (Method)handler;
    //      for(Object param : method.getParameterTypes())   {
    //         System.out.println(param.getClass().getName());
    //         if(param instanceof User)   {
    //            System.out.println("qwe");
    //         }
    //      }
    return true;
}

From source file:com.easysoft.jeap.controller.admin.LoginController.java

/**
 * // w  w w  .  jav  a 2 s .c o m
 * @param username
 * @param password
 * @return
 */
@RequestMapping("/login")
public ModelAndView login(String username, String password, HttpServletRequest request,
        HttpServletResponse response) {

    try {
        Map<String, Object> params = new HashMap<String, Object>();
        AdminUser adminUser = adminUserManager.login(username, password);
        request.getSession().setAttribute("admin_user_key", adminUser);
        List<Menu> rootMenus = menuManager.queryMenusByPid(0);
        params.put("rootMenus", rootMenus);
        return new ModelAndView("adminthemes/default/main", params);
    } catch (Exception e) {
        logger.error("!", e);
        try {
            response.sendRedirect("toLogin.do");
        } catch (IOException e1) {
            logger.error("?!", e1);
        }
    }
    return null;
}

From source file:org.artifactory.webapp.servlet.RepoFilter.java

private void doRepoListing(HttpServletRequest request, HttpServletResponse response, String servletPath,
        ArtifactoryRequest artifactoryRequest) throws ServletException, IOException {
    log.debug("Forwarding internally to an apache-style listing page.");
    if (!servletPath.endsWith("/")) {
        response.sendRedirect(HttpUtils.getServletContextUrl(request) + servletPath + "/");
        return;/*from  w w w.  ja  v  a2 s. c  om*/
    }
    request.setAttribute(ATTR_ARTIFACTORY_REPOSITORY_PATH, artifactoryRequest.getRepoPath());
    request.setAttribute(ATTR_ARTIFACTORY_REQUEST_PROPERTIES, artifactoryRequest.getProperties());

    RequestDispatcher dispatcher = request.getRequestDispatcher("/ui/nativeBrowser");
    dispatcher.forward(request, response);
}

From source file:controllers.UrlController.java

@RequestMapping(value = "/result/{pid}", method = RequestMethod.GET)
public void result(@PathVariable int pid, ModelMap model, HttpServletRequest request,
        HttpServletResponse response) throws SQLException, IOException {
    Poll_TblJDBCTemplate poll_tbljdbc = new Poll_TblJDBCTemplate();
    Poll_Tbl poll_tbl = poll_tbljdbc.getPoll(pid);
    response.sendRedirect(pid + "/" + poll_tbl.getPoll_link());
}

From source file:controllers.UrlController.java

@RequestMapping(value = "/geoviz/{pid}", method = RequestMethod.GET)
public void geoviz(@PathVariable int pid, ModelMap model, HttpServletRequest request,
        HttpServletResponse response) throws SQLException, IOException {
    Poll_TblJDBCTemplate poll_tbljdbc = new Poll_TblJDBCTemplate();
    Poll_Tbl poll_tbl = poll_tbljdbc.getPoll(pid);
    response.sendRedirect(pid + "/" + poll_tbl.getPoll_link());
}

From source file:com.estampate.corteI.servlet.guardarEstampa.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* ww w .ja  v  a 2s . c o m*/
 *
 * @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 {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    HttpSession objSesion = request.getSession(true);
    campos = new ArrayList<String>();
    //request.setAttribute("servlet", "ok");
    objSesion.setAttribute("servlet", "ok");
    //request.getRequestDispatcher("artista/administrarEstampa.jsp").forward(request, response);
    response.sendRedirect("artista/administrarEstampa.jsp");
    //    out.print(subioImagen);
    out.close();
}

From source file:com.arihant15.ActionServlet.java

@RequestMapping("/callback.arihant15")
public void doCallback(HttpServletRequest req, HttpServletResponse res) throws IOException {
    try {/*from  w w w  .j av a2s .co m*/
        AccessToken accessToken;
        Twitter twitter = (Twitter) req.getSession().getAttribute("t");
        RequestToken requestToken = (RequestToken) req.getSession().getAttribute("rToken");
        String verifier = req.getParameter("oauth_verifier");
        accessToken = twitter.getOAuthAccessToken(requestToken, verifier);
        req.getSession().removeAttribute("rToken");
    } catch (Exception e) {
        (res.getWriter()).println(e);
    }
    res.sendRedirect(req.getContextPath() + "/");
}

From source file:cn.itcast.bbs.controller.BbsServlet.java

private void deleteType(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    int typeId = Integer.parseInt(request.getParameter("typeId"));
    try {/*from w ww .ja v a  2  s.  com*/
        service.deleteType(typeId);
        response.sendRedirect(request.getContextPath());
    } catch (Exception e) {
        e.printStackTrace();
        request.setAttribute("message", "?");
        request.getRequestDispatcher("/WEB-INF/bbs/message.jsp").forward(request, response);
    }
}