本文整理匯總了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);
}