Package org.springframework.security.web

# Class DefaultRedirectStrategy

java.lang.Object
org.springframework.security.web.DefaultRedirectStrategy

All Implemented Interfaces:
  `RedirectStrategy`

public class DefaultRedirectStrategy extends Object implements RedirectStrategy
Simple implementation of `RedirectStrategy` which is the default used throughout the framework.

Since:
  3.0

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final org.apache.commons.logging.Log`
`logger`

## Constructor Summary

Constructors
Constructor
Description
`DefaultRedirectStrategy()`

## Method Summary

Modifier and Type
Method
Description
`protected String`
`calculateRedirectUrl(String contextPath, String url)`
`protected boolean`
`isContextRelative()`
Returns `true`, if the redirection URL should be calculated minus the protocol and context path (defaults to `false`).
`void`
`sendRedirect(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String url)`
Redirects the response to the supplied URL.
`void`
`setContextRelative(boolean useRelativeContext)`
If `true`, causes any redirection URLs to be calculated minus the protocol and context path (defaults to `false`).
`void`
`setStatusCode(org.springframework.http.HttpStatus statusCode)`
Sets the HTTP status code to use.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### logger

protected final org.apache.commons.logging.Log logger

## Constructor Details

### DefaultRedirectStrategy

public DefaultRedirectStrategy()

## Method Details

### sendRedirect

public void sendRedirect(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String url) throws IOException
Redirects the response to the supplied URL.

If `contextRelative` is set, the redirect value will be the value after the request context path. Note that this will result in the loss of protocol information (HTTP or HTTPS), so will cause problems if a redirect is being performed to change to HTTPS, for example.

Specified by:
  `sendRedirect` in interface `RedirectStrategy`
Parameters:
  `request` - the current request
  `response` - the response to redirect
  `url` - the target URL to redirect to, for example "/login"
Throws:
  `IOException`

### calculateRedirectUrl

protected String calculateRedirectUrl(String contextPath, String url)

### setContextRelative

public void setContextRelative(boolean useRelativeContext)
If `true`, causes any redirection URLs to be calculated minus the protocol and context path (defaults to `false`).

### isContextRelative

protected boolean isContextRelative()
Returns `true`, if the redirection URL should be calculated minus the protocol and context path (defaults to `false`).

### setStatusCode

public void setStatusCode(org.springframework.http.HttpStatus statusCode)
Sets the HTTP status code to use. The default is `HttpStatus.FOUND`.

Note that according to RFC 7231, with `HttpStatus.FOUND`, a user agent MAY change the request method from POST to GET for the subsequent request. If this behavior is undesired, `HttpStatus.TEMPORARY_REDIRECT` can be used instead.

Parameters:
  `statusCode` - the HTTP status code to use.
Since:
  6.2