本文整理汇总了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);
}
示例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();
}
示例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);
}
示例4: encodeRedirectURLRewrite
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public String encodeRedirectURLRewrite(HttpServletResponse resp, String url) {
return resp.encodeRedirectURL(url);
}