jetty-server/src/main/java/org/eclipse/jetty/server/Response.java
/**
     * 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} headers
     * @throws IOException if unable to send the redirect
     */
Sends a response with one of the 300 series redirection codes.
@param code the redirect status code
@param location the location to send in  Location headers
@throws IOException if unable to send the redirect
Sends a response with one of the 300 series redirection codes . @param code the redirect status code @param location the location to send in Location 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();
        if (!URIUtil.hasScheme(location))
        {
            StringBuilder buf = _channel.getRequest().getRootURL();
            if (location.startsWith("/"))
            {
                location = URIUtil.canonicalEncodedPath(location);
            }
            else
            {
                String path = _channel.getRequest().getRequestURI();
                String parent = (path.endsWith("/")) ? path : URIUtil.parentPath(path);
                location = URIUtil.canonicalEncodedPath(URIUtil.addEncodedPaths(parent, location));
                if (location != null && !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();
    }
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 ( ) ; if ( ! URIUtil . hasScheme ( location ) ) { StringBuilder buf = _channel . getRequest ( ) . getRootURL ( ) ; if ( location . startsWith ( "/" ) ) { location = URIUtil . canonicalEncodedPath ( location ) ; } else { String path = _channel . getRequest ( ) . getRequestURI ( ) ; String parent = ( path . endsWith ( "/" ) ) ? path : URIUtil . parentPath ( path ) ; location = URIUtil . canonicalEncodedPath ( URIUtil . addEncodedPaths ( parent , location ) ) ; if ( location != null && ! 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 ( ) ; }
Sends a response with one of the 300 series redirection codes.
Sends a response with one of the 300 series redirection codes .
// absolute in context // relative to request