List of usage examples for javax.servlet.http HttpServletResponse sendRedirect
public void sendRedirect(String location) throws IOException;
From source file:com.easou.common.util.CommonUtils.java
/** * Sends the redirect message and captures the exceptions that we can't * possibly do anything with./*from w w w. j a v a 2 s . c om*/ * * @param response * the HttpServletResponse. CANNOT be NULL. * @param url * the url to redirect to. */ public static void sendRedirect(final HttpServletResponse response, final String url) { try { response.sendRedirect(url); } catch (final Exception e) { LOG.warn(e.getMessage(), e); } }
From source file:com.discovery.darchrow.http.ResponseUtil.java
/** * ?./*ww w . j a v a2 s . co m*/ * * @param response * HttpServletResponse * @param url * * @throws UncheckedIOException * the unchecked io exception */ public static void setNoCacheAndRedirect(HttpServletResponse response, String url) throws UncheckedIOException { setNoCacheHeader(response); try { response.sendRedirect(url); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:com.sunchenbin.store.feilong.servlet.http.ResponseUtil.java
/** * ./*from w ww .j a va 2 s . c o m*/ * <p> * {@link HttpServletResponse#sendRedirect(String)}?302??Location??Location?URL * </p> * <p> * {@link HttpServletResponse#sendRedirect(String)}?<span style="color:red">?return;</span>; <br> * ? {@link HttpServletResponse#sendRedirect(String)}??????????<br> * ????????? * </p> * * @param response * the response * @param url * the redirect location URL * @see HttpServletResponse#sendRedirect(String) * @since 1.2.2 */ public static void sendRedirect(HttpServletResponse response, String url) { try { response.sendRedirect(url); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:com.google.zxing.web.DecodeServlet.java
private static void handleException(ReaderException re, HttpServletResponse response) throws IOException { if (re instanceof NotFoundException) { log.info("Not found: " + re); response.sendRedirect("notfound.jspx"); } else if (re instanceof FormatException) { log.info("Format problem: " + re); response.sendRedirect("format.jspx"); } else if (re instanceof ChecksumException) { log.info("Checksum problem: " + re); response.sendRedirect("format.jspx"); } else {/*from w w w . ja va2 s.c o m*/ log.info("Unknown problem: " + re); response.sendRedirect("notfound.jspx"); } }
From source file:io.lavagna.web.helper.Redirector.java
public static void sendRedirect(HttpServletRequest req, HttpServletResponse resp, String page, Map<String, List<String>> params) throws IOException { WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(req.getServletContext()); String baseApplicationUrl = ctx.getBean(ConfigurationRepository.class).getValue(Key.BASE_APPLICATION_URL); UriComponents urlToRedirect = UriComponentsBuilder.fromHttpUrl(baseApplicationUrl).path(page) .queryParams(new LinkedMultiValueMap<>(params)).build(); resp.sendRedirect(urlToRedirect.toUriString()); }
From source file:info.magnolia.cms.util.RequestDispatchUtil.java
/** * Returns true if processing took place, even if it fails. *///from w ww . j a v a2 s .c o m public static boolean dispatch(String targetUri, HttpServletRequest request, HttpServletResponse response) { if (targetUri == null) { return false; } if (targetUri.startsWith(REDIRECT_PREFIX)) { String redirectUrl = StringUtils.substringAfter(targetUri, REDIRECT_PREFIX); try { if (isInternal(redirectUrl)) { redirectUrl = request.getContextPath() + redirectUrl; } response.sendRedirect(response.encodeRedirectURL(redirectUrl)); } catch (IOException e) { log.error("Failed to redirect to {}:{}", targetUri, e.getMessage()); } return true; } if (targetUri.startsWith(PERMANENT_PREFIX)) { String permanentUrl = StringUtils.substringAfter(targetUri, PERMANENT_PREFIX); try { if (isInternal(permanentUrl)) { if (isUsingStandardPort(request)) { permanentUrl = new URL(request.getScheme(), request.getServerName(), request.getContextPath() + permanentUrl).toExternalForm(); } else { permanentUrl = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath() + permanentUrl).toExternalForm(); } } response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); response.setHeader("Location", permanentUrl); } catch (MalformedURLException e) { log.error("Failed to create permanent url to redirect to {}:{}", targetUri, e.getMessage()); } return true; } if (targetUri.startsWith(FORWARD_PREFIX)) { String forwardUrl = StringUtils.substringAfter(targetUri, FORWARD_PREFIX); try { request.getRequestDispatcher(forwardUrl).forward(request, response); } catch (Exception e) { log.error("Failed to forward to {} - {}:{}", new Object[] { forwardUrl, ClassUtils.getShortClassName(e.getClass()), e.getMessage() }); } return true; } return false; }
From source file:com.orig.gls.web.category.Categoryw.java
public static void handleGoCategory(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(false); if ((String) session.getAttribute("uname") != null) { session.setAttribute("catfunc", request.getParameter("function")); session.setAttribute("categorytype", request.getParameter("categorytype")); session.setAttribute("content_page", "categories/mCategories_b.jsp"); } else {//from w w w.jav a 2s . com session.setAttribute("content_page", "sessionexp.jsp"); } response.sendRedirect("index.jsp"); }
From source file:com.trailmagic.image.ui.WebSupport.java
/** * If the request URI does not end with a /, redirects to the same URI * with a trailing /. Otherwise, does nothing. * * @param req the servlet request/*from w w w .j a v a 2 s. c om*/ * @param res the servlet response */ public static boolean handleDirectoryUrlRedirect(HttpServletRequest req, HttpServletResponse res) throws IOException { String uri = req.getRequestURI(); // if trailing / already, no work to do; we're done if (!uri.endsWith("/")) { StringBuffer newLocation = new StringBuffer(); newLocation.append(uri); newLocation.append("/"); if (req.getQueryString() != null) { newLocation.append("?"); newLocation.append(req.getQueryString()); } res.sendRedirect(newLocation.toString()); return true; } return false; }
From source file:com.zimbra.cs.service.ExternalUserProvServlet.java
private static void setCookieAndRedirect(HttpServletRequest req, HttpServletResponse resp, Account grantee) throws ServiceException, IOException { AuthToken authToken = AuthProvider.getAuthToken(grantee); authToken.encode(resp, false, req.getScheme().equals("https")); resp.sendRedirect("/"); }
From source file:com.vmware.identity.openidconnect.sample.RelyingPartyController.java
private static void sendRedirect(HttpServletResponse response, String target) { try {/*from w w w . j a v a 2s. c om*/ response.sendRedirect(target); } catch (IOException e) { throw new IllegalStateException(e); } }