当前位置: 首页>>代码示例>>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;未经允许,请勿转载。