當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServletResponse.encodeRedirectURL方法代碼示例

本文整理匯總了Java中javax.servlet.http.HttpServletResponse.encodeRedirectURL方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletResponse.encodeRedirectURL方法的具體用法?Java HttpServletResponse.encodeRedirectURL怎麽用?Java HttpServletResponse.encodeRedirectURL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.http.HttpServletResponse的用法示例。


在下文中一共展示了HttpServletResponse.encodeRedirectURL方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendRedirect

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public void sendRedirect(final HttpServletRequest request, final HttpServletResponse response, final String url) throws IOException {

	// The status is OK, not MOVED
	response.setStatus(status);

	// Write the UTF-8 JSON content
	response.setCharacterEncoding(StandardCharsets.UTF_8.name());
	response.setContentType("application/json");

	final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
	if (success && authentication instanceof CookieUsernamePasswordAuthenticationToken) {
		// Forward cookies from back-office
		((CookieUsernamePasswordAuthenticationToken) authentication).getCookies().forEach(cookie -> response.addHeader("Set-Cookie", cookie));
	}
	// Write the JSON data containing the redirection and the status
	final String redirectUrl = response.encodeRedirectURL(request.getContextPath() + url);
	IOUtils.write(String.format("{\"success\":%b,\"redirect\":\"%s\"}", success, redirectUrl), response.getOutputStream(),
			StandardCharsets.UTF_8);
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:21,代碼來源:RestRedirectStrategy.java

示例2: sendRedirect

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * Handle redirects with a status code that can in future support verbs other
 * than GET, thus supporting full REST functionality.
 * <p>
 * The target URL is included in the redirect text returned
 * <p>
 * At the end of this method, the output stream is closed.
 * 
 * @param request request (hence: the verb and any other information
 * relevant to a redirect)
 * @param response the response
 * @param target the target URL -unencoded
 *
 */
public static void sendRedirect(HttpServletRequest request,
    HttpServletResponse response,
    String target)
    throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Redirecting {} {} to {}",
        request.getMethod(), 
        request.getRequestURI(),
        target);
  }
  String location = response.encodeRedirectURL(target);
  response.setStatus(HttpServletResponse.SC_FOUND);
  response.setHeader(LOCATION, location);
  response.setContentType(MimeType.HTML);
  PrintWriter writer = response.getWriter();
  Page p = new Page(writer);
  p.html()
      .head().title("Moved")._()
      .body()
      .h1("Moved")
      .div()
        ._("Content has moved ")
        .a(location, "here")._()
      ._()._();
  writer.close();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:41,代碼來源:ProxyUtils.java

示例3: sendRedirect

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
private void sendRedirect(HttpServletRequest request, HttpServletResponse response) {

		String encodedRedirectURL = response.encodeRedirectURL(request.getContextPath() + "/");
		response.setStatus(HttpStatus.TEMPORARY_REDIRECT.value());
		response.setHeader("Location", encodedRedirectURL);
	}
 
開發者ID:Azanx,項目名稱:Smart-Shopping,代碼行數:7,代碼來源:RedirectWhenAuthenticatedInterceptor.java

示例4: encodeRedirectURLRewrite

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public String encodeRedirectURLRewrite(HttpServletResponse resp, String url) {
    return resp.encodeRedirectURL(url);
}
 
開發者ID:blackarbiter,項目名稱:Android_Code_Arbiter,代碼行數:4,代碼來源:UrlRewriting.java


注:本文中的javax.servlet.http.HttpServletResponse.encodeRedirectURL方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。