spring-framework / org.springframework.web.filter / CharacterEncodingFilter

CharacterEncodingFilter

open class CharacterEncodingFilter : OncePerRequestFilter

Servlet Filter that allows one to specify a character encoding for requests. This is useful because current browsers typically do not set a character encoding even if specified in the HTML page or form.

This filter can either apply its encoding if the request does not already specify an encoding, or enforce this filter's encoding in any case ("forceEncoding"="true"). In the latter case, the encoding will also be applied as default response encoding (although this will usually be overridden by a full content type set in the view).

Author
Juergen Hoeller

Since
15.03.2004

See Also
#setEncoding#setForceEncodingjavax.servlet.http.HttpServletRequest#setCharacterEncodingjavax.servlet.http.HttpServletResponse#setCharacterEncoding

Constructors

<init>

CharacterEncodingFilter()

Create a default CharacterEncodingFilter, with the encoding to be set via #setEncoding.

CharacterEncodingFilter(encoding: String)
CharacterEncodingFilter(encoding: String, forceEncoding: Boolean)
CharacterEncodingFilter(encoding: String, forceRequestEncoding: Boolean, forceResponseEncoding: Boolean)

Create a CharacterEncodingFilter for the given encoding.

Functions

getEncoding

open fun getEncoding(): String

Return the configured encoding for requests and/or responses.

isForceRequestEncoding

open fun isForceRequestEncoding(): Boolean

Return whether the encoding should be forced on requests

isForceResponseEncoding

open fun isForceResponseEncoding(): Boolean

Return whether the encoding should be forced on responses.

setEncoding

open fun setEncoding(encoding: String): Unit

Set the encoding to use for requests. This encoding will be passed into a javax.servlet.http.HttpServletRequest#setCharacterEncoding call.

Whether this encoding will override existing request encodings (and whether it will be applied as default response encoding as well) depends on the "forceEncoding" flag.

setForceEncoding

open fun setForceEncoding(forceEncoding: Boolean): Unit

Set whether the configured encoding of this filter is supposed to override existing request and response encodings.

Default is "false", i.e. do not modify the encoding if javax.servlet.http.HttpServletRequest#getCharacterEncoding() returns a non-null value. Switch this to "true" to enforce the specified encoding in any case, applying it as default response encoding as well.

This is the equivalent to setting both #setForceRequestEncoding(boolean) and #setForceResponseEncoding(boolean).

setForceRequestEncoding

open fun setForceRequestEncoding(forceRequestEncoding: Boolean): Unit

Set whether the configured encoding of this filter is supposed to override existing request encodings.

Default is "false", i.e. do not modify the encoding if javax.servlet.http.HttpServletRequest#getCharacterEncoding() returns a non-null value. Switch this to "true" to enforce the specified encoding in any case.

setForceResponseEncoding

open fun setForceResponseEncoding(forceResponseEncoding: Boolean): Unit

Set whether the configured encoding of this filter is supposed to override existing response encodings.

Default is "false", i.e. do not modify the encoding. Switch this to "true" to enforce the specified encoding for responses in any case.