Tabnine Logo
HttpServletResponse.sendRedirect
Code IndexAdd Tabnine to your IDE (free)

How to use
sendRedirect
method
in
javax.servlet.http.HttpServletResponse

Best Java code snippets using javax.servlet.http.HttpServletResponse.sendRedirect (Showing top 20 results out of 8,676)

Refine searchRefine arrow

  • HttpServletRequest.getParameter
  • HttpServletRequest.getSession
  • HttpServletRequest.getContextPath
  • HttpServletRequest.getRequestURI
  • HttpSession.getAttribute
  • HttpSession.setAttribute
  • FilterChain.doFilter
origin: stackoverflow.com

 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  String username = request.getParameter("username");
  String password = request.getParameter("password");
  User user = userService.find(username, password);

  if (user != null) {
    request.getSession().setAttribute("user", user); // Login user.
    response.sendRedirect("home"); // Redirect to home page.
  } else {
    request.setAttribute("message", "Unknown username/password. Please retry."); // Store error message in request scope.
    request.getRequestDispatcher("/WEB-INF/login.jsp").forward(request, response); // Forward to JSP page to redisplay login form with error.
  }
}
origin: stackoverflow.com

@WebServlet(name = "LogoutServlet", urlPatterns = {"/logout"})
public class LogoutServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 HttpSession session = request.getSession(false);
 // Destroys the session for this user.
 if (session != null)
   session.invalidate();
 // Redirects back to the initial page.
 response.sendRedirect(request.getContextPath());
}
}
origin: jenkinsci/jenkins

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
  HttpServletRequest req = (HttpServletRequest) request;
  /* allow signup from the Jenkins home page, or /manage, which is where a /configureSecurity form redirects to */
  if(req.getRequestURI().equals(req.getContextPath()+"/") || req.getRequestURI().equals(req.getContextPath() + "/manage")) {
    if (needsToCreateFirstUser()) {
      ((HttpServletResponse)response).sendRedirect("securityRealm/firstUser");
    } else {// the first user already created. the role of this filter is over.
      PluginServletFilter.removeFilter(this);
      chain.doFilter(request,response);
    }
  } else
    chain.doFilter(request,response);
}
origin: alibaba/druid

public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  String contextPath = request.getContextPath();
  String servletPath = request.getServletPath();
  String requestURI = request.getRequestURI();
    String usernameParam = request.getParameter(PARAM_NAME_USERNAME);
    String passwordParam = request.getParameter(PARAM_NAME_PASSWORD);
    if (username.equals(usernameParam) && password.equals(passwordParam)) {
      request.getSession().setAttribute(SESSION_USER_KEY, username);
      response.getWriter().print("success");
    } else {
    || path.startsWith("/img"))) {
    if (contextPath.equals("") || contextPath.equals("/")) {
      response.sendRedirect("/druid/login.html");
    } else {
      if ("".equals(path)) {
        response.sendRedirect("druid/login.html");
      } else {
        response.sendRedirect("login.html");
      response.sendRedirect("/druid/index.html");
    } else {
      response.sendRedirect("druid/index.html");
    response.sendRedirect("index.html");
    return;
origin: SonarSource/sonarqube

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
 HttpServletRequest request = (HttpServletRequest) servletRequest;
 HttpServletResponse response = (HttpServletResponse) servletResponse;
 String path = extractPath(request);
 Predicate<Redirect> match = redirect -> redirect.test(path);
 List<Redirect> redirects = REDIRECTS.stream()
  .filter(match)
  .collect(MoreCollectors.toList());
 switch (redirects.size()) {
  case 0:
   chain.doFilter(request, response);
   break;
  case 1:
   response.sendRedirect(redirects.get(0).apply(request));
   break;
  default:
   throw new IllegalStateException(format("Multiple redirects have been found for '%s'", path));
 }
}
origin: DeemOpen/zkui

String searchStr = request.getParameter("searchStr").trim();
String authRole = (String) request.getSession().getAttribute("authRole");
      request.getSession().setAttribute("flashMsg", "Node created!");
      dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "Creating node: " + currentPath + newNode);
    response.sendRedirect("/home?zkPath=" + displayPath);
    break;
  case "Save Property":
      dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "Saving Property: " + currentPath + "," + newProperty + "=" + newValue);
    response.sendRedirect("/home?zkPath=" + displayPath);
    break;
  case "Update Property":
      dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "Updating Property: " + currentPath + "," + newProperty + "=" + newValue);
    response.sendRedirect("/home?zkPath=" + displayPath);
    break;
  case "Search":
    response.sendRedirect("/home?zkPath=" + displayPath);
    break;
  default:
    response.sendRedirect("/home");
origin: azkaban/azkaban

private void handleUpload(final HttpServletRequest req, final HttpServletResponse resp,
  final Map<String, Object> multipart, final Session session) throws ServletException,
  IOException {
 final HashMap<String, String> ret = new HashMap<>();
 final String projectName = (String) multipart.get("project");
 ajaxHandleUpload(req, resp, ret, multipart, session);
 if (ret.containsKey("error")) {
  setErrorMessageInCookie(resp, ret.get("error"));
 }
 if (ret.containsKey("warn")) {
  setWarnMessageInCookie(resp, ret.get("warn"));
 }
 resp.sendRedirect(req.getRequestURI() + "?project=" + projectName);
}
origin: ehcache/ehcache3

 @Override
 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
  String peepText = req.getParameter("peep");

  try {

   PeeperServletContextListener.DATA_STORE.addPeep(peepText);
   resp.sendRedirect("peep");

  } catch (Exception e) {
   throw new ServletException("Error saving peep", e);
  }
 }
}
origin: alibaba/nacos

HttpServletResponse resp = (HttpServletResponse) servletResponse;
String urlString = req.getRequestURI() + "?" + req.getQueryString();
Map<String, Integer> limitedUrlMap = Switch.getLimitedUrlMap();
if (req.getRequestURI().contains(UtilsAndCommons.NACOS_NAMING_INSTANCE_CONTEXT) && !RaftCore.isLeader()) {
    String url = "http://" + RaftCore.getLeader().ip + req.getRequestURI() + "?" + req.getQueryString();
    try {
      resp.sendRedirect(url);
    } catch (Exception ignore) {
      Loggers.SRV_LOG.warn("[DISTRO-FILTER] request failed: " + url);
  filterChain.doFilter(req, resp);
  return;
  filterChain.doFilter(req, resp);
  return;
  filterChain.doFilter(req, resp);
  return;
        + req.getRequestURI() + "?" + req.getQueryString();
    try {
      resp.sendRedirect(url);
    } catch (Exception ignore) {
      Loggers.SRV_LOG.warn("[DISTRO-FILTER] request failed: " + url);
origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

HttpSession session = request.getSession();
  chain.doFilter(req, res);
  return;
    session.setAttribute(LOGIN_HINT, loginHint);
  } else {
    session.removeAttribute(LOGIN_HINT);
        chain.doFilter(req, res);
      } else {
        logger.info("Client requested no prompt");
            response.sendRedirect(uriBuilder.toString());
            return;
      if (session.getAttribute(PROMPTED) == null) {
        session.setAttribute(PROMPT_REQUESTED, Boolean.TRUE);
          chain.doFilter(req, res);
        } else {
      Date authTime = (Date) session.getAttribute(AuthenticationTimeStamper.AUTH_TIMESTAMP);
origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

HttpSession session = request.getSession();
  response.sendRedirect(issResp.getRedirectUrl());
} else {
  String issuer = issResp.getIssuer();
    session.setAttribute(TARGET_SESSION_VARIABLE, issResp.getTargetLinkUri());
  session.setAttribute(ISSUER_SESSION_VARIABLE, serverConfig.getIssuer());
  session.setAttribute(REDIRECT_URI_SESION_VARIABLE, redirectUri);
  response.sendRedirect(authRequest);
origin: DeemOpen/zkui

    uploadFileName = scmServer + scmFileRevision + "@" + scmFilePath;
    logger.debug("P4 file Processing " + uploadFileName);
    dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "Importing P4 File: " + uploadFileName + "<br/>" + "Overwrite: " + scmOverwrite);
    URL url = new URL(uploadFileName);
    URLConnection conn = url.openConnection();
    dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "Uploading File: " + uploadFileName + "<br/>" + "Overwrite: " + scmOverwrite);
    inpStream = new ByteArrayInputStream(sbFile.toString().getBytes());
  for (String line : importFile) {
    if (line.startsWith("-")) {
      dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "File: " + uploadFileName + ", Deleting Entry: " + line);
    } else {
      dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "File: " + uploadFileName + ", Adding Entry: " + line);
  request.getSession().setAttribute("flashMsg", "Import Completed!");
  response.sendRedirect("/home");
} catch (FileUploadException | IOException | InterruptedException | KeeperException ex) {
  logger.error(Arrays.toString(ex.getStackTrace()));
origin: BroadleafCommerce/BroadleafCommerce

String notification = (String) request.getAttribute(STATECHANGENOTIFICATIONTOKEN);
if (Boolean.valueOf(notification)) {
  String uri = request.getRequestURI();
  Enumeration<String> params = request.getParameterNames();
  StringBuilder sb = new StringBuilder();
      sb.append(request.getParameter(param));
    response.sendError(403);
  response.sendRedirect(encoded);
  return true;
origin: DeemOpen/zkui

Properties globalProps = (Properties) getServletContext().getAttribute("globalProps");
Map<String, Object> templateParam = new HashMap<>();
HttpSession session = request.getSession(true);
session.setMaxInactiveInterval(Integer.valueOf(globalProps.getProperty("sessionTimeout")));
String username = request.getParameter("username");
String password = request.getParameter("password");
String role = null;
Boolean authenticated = false;
  session.setAttribute("authName", username);
  session.setAttribute("authRole", role);
  response.sendRedirect("/home");
} else {
  session.setAttribute("flashMsg", "Invalid Login");
  ServletUtil.INSTANCE.renderHtml(request, response, templateParam, "login.ftl.html");
origin: BroadleafCommerce/BroadleafCommerce

@Override
public void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url) throws IOException {
  if (!url.startsWith("/")) {
    if (StringUtils.equals(request.getParameter("successUrl"), url) || StringUtils.equals(request.getParameter("failureUrl"), url)) {
      validateRedirectUrl(request.getContextPath(), url, request.getServerName(), request.getServerPort());
    }
  }
  String redirectUrl = calculateRedirectUrl(request.getContextPath(), url);
  redirectUrl = response.encodeRedirectURL(redirectUrl);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Redirecting to '" + url + "'");
  }
  response.sendRedirect(redirectUrl);
}
origin: gocd/gocd

public void render(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception {
  String contextpath = request.getContextPath();
  String params = "";
  Map queryString = (Map) model.get("params");
  if (queryString != null) {
    for (Object key : queryString.keySet()) {
      String value = (String) queryString.get(key);
      if (value != null) {
        if (params.length() > 0) {
          params += "&";
        }
        params += key + "=" + URLEncoder.encode(value, "UTF-8");
      }
    }
  }
  String paramString = params.isEmpty() ? "" : "?" + params;
  response.sendRedirect(contextpath + "/tab" + target + paramString);
}
origin: DeemOpen/zkui

  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
      logger.debug("Logout Action!");
      Properties globalProps = (Properties) getServletContext().getAttribute("globalProps");
      String zkServer = globalProps.getProperty("zkServer");
      String[] zkServerLst = zkServer.split(",");
      ZooKeeper zk = ServletUtil.INSTANCE.getZookeeper(request, response, zkServerLst[0],globalProps);
      request.getSession().invalidate();
      zk.close();
      response.sendRedirect("/login");
    } catch (InterruptedException ex) {
      logger.error(Arrays.toString(ex.getStackTrace()));
      ServletUtil.INSTANCE.renderError(request, response, ex.getMessage());
    }

  }
}
origin: geoserver/geoserver

  chain.doFilter(request, response);
  return;
    .append(":")
    .append(sslPort)
    .append(httpRequest.getContextPath())
    .append(httpRequest.getServletPath());
((HttpServletResponse) response).sendRedirect(redirectURL);
origin: azkaban/azkaban

private void handleRemoveProject(final HttpServletRequest req,
  final HttpServletResponse resp, final Session session) throws ServletException,
  IOException {
 final User user = session.getUser();
 final String projectName = getParam(req, "project");
 final Project project = this.projectManager.getProject(projectName);
 if (project == null) {
  this.setErrorMessageInCookie(resp, "Project " + projectName
    + " doesn't exist.");
  resp.sendRedirect(req.getContextPath());
  return;
 }
 if (!hasPermission(project, user, Type.ADMIN)) {
  this.setErrorMessageInCookie(resp,
    "Cannot delete. User '" + user.getUserId() + "' is not an ADMIN.");
  resp.sendRedirect(req.getRequestURI() + "?project=" + projectName);
  return;
 }
 removeAssociatedSchedules(project);
 try {
  this.projectManager.removeProject(project, user);
 } catch (final ProjectManagerException e) {
  this.setErrorMessageInCookie(resp, e.getMessage());
  resp.sendRedirect(req.getRequestURI() + "?project=" + projectName);
  return;
 }
 this.setSuccessMessageInCookie(resp, "Project '" + projectName
   + "' was successfully deleted and associated schedules are removed.");
 resp.sendRedirect(req.getContextPath());
}
origin: AsyncHttpClient/async-http-client

 httpResponse.sendRedirect(httpRequest.getHeader("X-redirect"));
 return;
while (i.hasMoreElements()) {
 headerName = i.nextElement();
 httpResponse.addHeader("X-" + headerName, httpRequest.getParameter(headerName));
 requestBody.append(headerName);
 requestBody.append("_");
javax.servlet.httpHttpServletResponsesendRedirect

Javadoc

Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer. The buffer will be replaced with the data set by this method. Calling this method sets the status code to #SC_FOUND 302 (Found). This method can accept relative URLs;the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root. If the location is relative with two leading '/' the container interprets it as a network-path reference (see RFC 3986: Uniform Resource Identifier (URI): Generic Syntax, section 4.2 "Relative Reference").

If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

Popular methods of HttpServletResponse

  • setContentType
  • setStatus
  • getWriter
  • getOutputStream
  • setHeader
    Sets a response header with the given name and value. If the header had already been set, the new va
  • sendError
    Sends an error response to the client using the specified status. The server defaults to creating th
  • addHeader
    Adds a response header with the given name and value. This method allows response headers to have mu
  • setCharacterEncoding
  • setContentLength
  • addCookie
    Adds the specified cookie to the response. This method can be called multiple times to set more than
  • setDateHeader
    Sets a response header with the given name and date-value. The date is specified in terms of millise
  • flushBuffer
  • setDateHeader,
  • flushBuffer,
  • isCommitted,
  • encodeRedirectURL,
  • getStatus,
  • reset,
  • encodeURL,
  • getCharacterEncoding,
  • getContentType

Popular in Java

  • Creating JSON documents from java classes using gson
  • onCreateOptionsMenu (Activity)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • setRequestProperty (URLConnection)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now