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:protocolo.config.AuthenticationInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
    if (request.getSession().getAttribute("usuario_logado") == null) {
        String uri = request.getRequestURI();
        if (uri.endsWith("/Protocolo.uneb") || uri.endsWith("create-protocol") || uri.endsWith("/loginForm")
                || uri.endsWith("/login") || uri.endsWith("/add") || uri.endsWith("/search")) {
            return true;
        } else {/* w w w  .  jav  a 2  s  . c o m*/
            response.sendRedirect("/Protocolo.uneb/loginForm");
            return false;
        }
    } else {
        User user = (User) request.getSession().getAttribute("usuario_logado");
        if (user.getType() == UserType.ADMIN) {
            String uri = request.getRequestURI();
            if (uri.endsWith("/loginForm") || uri.endsWith("/login") || uri.endsWith("/menu")) {
                response.sendRedirect("/Protocolo.uneb/config");
                return false;
            } else {
                return true;
            }
        } else {
            String uri = request.getRequestURI();
            if (uri.endsWith("/loginForm") || uri.endsWith("/login")) {
                response.sendRedirect("/Protocolo.uneb/menu");
                return false;
            } else {
                return true;
            }
        }
    }
}

From source file:com.ayovel.nian.servlet.UserBaseServlet.java

/**
 * ??/*  w w  w.  j a v  a2s . c  o m*/
 */
@Override
protected void doPut(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String action = request.getParameter(RestConstants.ACTION_PARAM);
    String userid = request.getParameter(RestConstants.USER_ID);

    JSONObject json;
    if (action.equals(RestConstants.USER_LOGIN)) {
        json = userLogin(request, response);
        userid = (String) json.get("userid");
        response.sendRedirect("mainpage");//?
        if (StringUtils.isNotEmpty(userid)) {
            response.sendRedirect("mainpage");//?
        }
    } else if (action.equals(RestConstants.USER_REG)) {
        json = getUserReg(request, response);
        userid = (String) json.get("userid");
        if (StringUtils.isNotEmpty(userid)) {
            response.sendRedirect("mainpage");//?
        }

    } else {//userid?
        if (StringUtils.isEmpty(userid)) {
            response.sendRedirect("userlogin");//?
        }
    }

    if (action.equals(RestConstants.USER_HOME)) {
        json = getUserHome(request, response);
    } else if (action.equals(RestConstants.USER_INFO)) {
        json = getUserInfo(request, response);
    } else {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0303,
                RestConstants.ACTION_PARAM, action);
    }

    if (json != null) {
        sendJsonResponse(response, HttpServletResponse.SC_OK, json);
    } else {
        response.setStatus(HttpServletResponse.SC_OK);
    }
}

From source file:com.streamsets.lib.security.http.SSOUserAuthenticator.java

Authentication redirectToLogout(HttpServletResponse httpRes) throws ServerAuthException {
    String urlToLogout = getSsoService().getLogoutUrl();
    try {/*  w ww .j av a2 s.  c o  m*/
        LOG.debug("Redirecting to logout '{}'", urlToLogout);
        httpRes.sendRedirect(urlToLogout);
        return Authentication.SEND_SUCCESS;
    } catch (IOException ex) {
        throw new ServerAuthException(
                Utils.format("Could not redirect to '{}': {}", urlToLogout, ex.toString(), ex));
    }
}

From source file:com.intelligentz.appointmentz.controllers.deleteRPI.java

@Override
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    try {/*from  ww w .  j  av a  2s.c o m*/
        String serial = req.getParameter("serial");
        connection = DBConnection.getDBConnection().getConnection();
        String SQL1 = "delete from rpi where serial=?";
        preparedStmt = connection.prepareStatement(SQL1);
        preparedStmt.setString(1, serial);
        // execute the preparedstatement
        preparedStmt.execute();
        res.sendRedirect("./equipments?status=Successfully Deleted Device Serial:" + serial);
    } catch (SQLException | PropertyVetoException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
        res.sendRedirect("./error.jsp?error=Error in delettiing device!\n+" + ex.toString() + "");
    } finally {
        try {
            DbUtils.closeQuietly(resultSet);
            DbUtils.closeQuietly(preparedStmt);
            DbUtils.close(connection);
        } catch (SQLException ex) {
            Logger.getLogger(register.class.getName()).log(Level.SEVERE, ex.toString(), ex);
        }
    }
}

From source file:au.edu.anu.orcid.security.OrcidAuthenticationSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    LOGGER.debug("User {} has authenticated", authentication.getName());

    if (authentication.getName().startsWith("u")) {
        String newPath = request.getContextPath() + "/rest/uid/" + authentication.getName() + "/import";
        LOGGER.debug("User {} logged in, redirecting the user to: {}", authentication.getName(), newPath);
        response.sendRedirect(newPath);
    } else {//from  ww w.j  av a  2 s . c o  m
        response.sendRedirect(request.getContextPath() + "/");
    }
}

From source file:at.gv.egiz.pdfas.web.helper.PdfAsHelper.java

public static void gotoProvidePdf(ServletContext context, HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    if (PdfAsHelper.getFromDataUrl(request)) {
        response.sendRedirect(generateProvideURL(request, response));
    } else {//from w ww .j av  a 2 s . co  m
        RequestDispatcher dispatcher = context.getRequestDispatcher(PDF_PROVIDE_PAGE);
        dispatcher.forward(request, response);
    }
}

From source file:edu.pitt.rest.userlistws.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// w w  w .j a  v a 2  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 {
    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();

    try {

        HttpSession session = request.getSession(true);

        if (Security.checkHijackedSession(session, request)) {
            response.sendRedirect("index.jsp");
        }

        String lastname = "";
        if (request.getParameter("lastname") != null) {
            lastname = request.getParameter("lastname").toString();
        }

        MySqlDbUtilities db = new MySqlDbUtilities();
        String sql = "SELECT * FROM userInfo ";
        if (!lastname.equals("")) {
            sql += "WHERE lastName LIKE '" + lastname + "%" + "' ";
        }
        sql += "LIMIT 20;";
        JSONArray fullUserList = new JSONArray();
        ResultSet rs = db.getResultSet(sql);

        /*
        Had way too many connections, flooded the mysql server. Needed to
        terminate connections so, manually get the db and close the connection
        changed closedbconnection() to public.
                
        Repeated steps in diagnosisws and symptomws.
                
        Mysql: show processlist (shows all connections)
        */
        while (rs.next()) {
            User user = new User(rs.getString("userId"));
            fullUserList.put(user.getUserInfoAsJSON());
            user.getDb().closeDbConnection();
        }

        StringWriter sw = new StringWriter();
        fullUserList.write(sw);
        out.print(sw.toString());
    } catch (SQLException ex) {
        Logger.getLogger(patientvisitws.class.getName()).log(Level.SEVERE, null, ex);
    } catch (JSONException ex) {
        Logger.getLogger(patientvisitws.class.getName()).log(Level.SEVERE, null, ex);
    }

    finally {
        out.close();
    }
}

From source file:io.muic.ooc.webapp.servlet.LoginServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // do login post logic
    // extract username and password from request
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    if (!StringUtils.isBlank(username) && !StringUtils.isBlank(password)) {
        if (securityService.authenticate(username, password, request)) {
            response.sendRedirect("/");
        } else {/*from  ww w. jav a  2s. c o m*/
            String error = "Wrong username or password.";
            request.setAttribute("error", error);
            RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/login.jsp");
            rd.include(request, response);
        }
    } else {
        String error = "Username or password is missing.";
        request.setAttribute("error", error);
        RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/login.jsp");
        rd.include(request, response);
    }

    // check username and password against database
    // if valid then set username attribute to session via securityService
    // else put error message to render error on the login form

}

From source file:org.dspace.app.webui.cris.controller.MyRPController.java

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Context context = UIUtil.obtainContext(request);
    EPerson currUser = context.getCurrentUser();
    if (currUser == null) {
        throw new ServletException(
                "Wrong data or configuration: access to the my rp servlet without a valid user: there is no user logged in or the user's netid is null");
    }/* w w w. j  a  v a2s  . c  o  m*/

    if (AuthorizeManager.isAdmin(context)) {
        response.sendRedirect(request.getContextPath() + "/dspace-admin/");
    } else {
        Integer id = currUser.getID();
        ResearcherPage rp = applicationService.getResearcherPageByEPersonId(id);
        if (rp != null && rp.getStatus() != null && rp.getStatus().booleanValue()) {
            response.sendRedirect(
                    request.getContextPath() + "/rp/" + ResearcherPageUtils.getPersistentIdentifier(rp));
        } else {
            // the researcher page is not active so redirect the user to the home page
            response.sendRedirect(request.getContextPath() + "/");
        }
    }
    // nothing to save so abort the context to release resources
    context.abort();
    return null;
}

From source file:com.groupon.odo.controllers.ConfigurationInterceptor.java

/**
 * This will check to see if certain configuration values exist from the ConfigurationService
 * If not then it redirects to the configuration screen
 */// w  w  w  .  j  av a  2 s  .c  om
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {

    String queryString = request.getQueryString() == null ? "" : request.getQueryString();

    if (ConfigurationService.getInstance().isValid() || request.getServletPath().startsWith("/configuration")
            || request.getServletPath().startsWith("/resources")
            || queryString.contains("requestFromConfiguration=true")) {
        return true;
    } else {
        response.sendRedirect("configuration");
        return false;
    }
}