本文整理汇总了Java中javax.servlet.http.HttpServletResponse.SC_MULTIPLE_CHOICES属性的典型用法代码示例。如果您正苦于以下问题:Java HttpServletResponse.SC_MULTIPLE_CHOICES属性的具体用法?Java HttpServletResponse.SC_MULTIPLE_CHOICES怎么用?Java HttpServletResponse.SC_MULTIPLE_CHOICES使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.servlet.http.HttpServletResponse
的用法示例。
在下文中一共展示了HttpServletResponse.SC_MULTIPLE_CHOICES属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doResponseRedirectOrNotModifiedLogic
protected boolean doResponseRedirectOrNotModifiedLogic(HttpServletRequest servletRequest, HttpServletResponse servletResponse,
HttpResponse proxyResponse, int statusCode) throws ServletException, IOException {
// Check if the proxy response is a redirect
// The following code is adapted from org.tigris.noodle.filters.CheckForRedirect
if (statusCode >= HttpServletResponse.SC_MULTIPLE_CHOICES /* 300 */
&& statusCode < HttpServletResponse.SC_NOT_MODIFIED /* 304 */) {
Header locationHeader = proxyResponse.getLastHeader(HttpHeaders.LOCATION);
if (locationHeader == null) {
throw new ServletException(
"Received status code: " + statusCode + " but no " + HttpHeaders.LOCATION + " header was found in the response");
}
// Modify the redirect to go to this proxy servlet rather that the proxied host
String locStr = rewriteUrlFromResponse(servletRequest, locationHeader.getValue());
servletResponse.sendRedirect(locStr);
return true;
}
// 304 needs special handling. See:
// http://www.ics.uci.edu/pub/ietf/http/rfc1945.html#Code304
// We get a 304 whenever passed an 'If-Modified-Since'
// header and the data on disk has not changed; server
// responds w/ a 304 saying I'm not going to send the
// body because the file has not changed.
if (statusCode == HttpServletResponse.SC_NOT_MODIFIED) {
servletResponse.setIntHeader(HttpHeaders.CONTENT_LENGTH, 0);
servletResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return true;
}
return false;
}
示例2: sendRedirect
/**
* Sends a response with one of the 300 series redirection codes.
* @param code the redirect status code
* @param location the location to send in <code>Location</code> headers
* @throws IOException if unable to send the redirect
*/
public void sendRedirect(int code, String location) throws IOException
{
if ((code < HttpServletResponse.SC_MULTIPLE_CHOICES) || (code >= HttpServletResponse.SC_BAD_REQUEST))
throw new IllegalArgumentException("Not a 3xx redirect code");
if (isIncluding())
return;
if (location == null)
throw new IllegalArgumentException();
/*
* The new http spec now allows to redirect to relative urls. So we comment
* out below section to avoid wrongly prepending http scheme to the url if
* GitPlex running with http protocol is exposed to outside as https prococol
* via reverse proxy
*/
/*
if (!URIUtil.hasScheme(location))
{
StringBuilder buf = _channel.getRequest().getRootURL();
if (location.startsWith("/"))
{
// absolute in context
location=URIUtil.canonicalPath(location);
}
else
{
// relative to request
String path=_channel.getRequest().getRequestURI();
String parent=(path.endsWith("/"))?path:URIUtil.parentPath(path);
location=URIUtil.canonicalPath(URIUtil.addPaths(parent,location));
if (!location.startsWith("/"))
buf.append('/');
}
if(location==null)
throw new IllegalStateException("path cannot be above root");
buf.append(location);
location=buf.toString();
}
*/
resetBuffer();
setHeader(HttpHeader.LOCATION, location);
setStatus(code);
closeOutput();
}