当前位置: 首页>>代码示例>>Java>>正文


Java HttpServletResponse.SC_MULTIPLE_CHOICES属性代码示例

本文整理汇总了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;
}
 
开发者ID:bluecreator,项目名称:http-agent,代码行数:30,代码来源:AgentServlet.java

示例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();
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:56,代码来源:Response.java


注:本文中的javax.servlet.http.HttpServletResponse.SC_MULTIPLE_CHOICES属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。