Package com.helger.servlet.filter
Class CharacterEncodingFilter
- java.lang.Object
-
- com.helger.servlet.filter.AbstractServletFilter
-
- com.helger.servlet.filter.AbstractHttpServletFilter
-
- com.helger.servlet.filter.CharacterEncodingFilter
-
- All Implemented Interfaces:
jakarta.servlet.Filter
public class CharacterEncodingFilter extends AbstractHttpServletFilter
Special servlet filter that applies a certain encoding to a request and a response. This must be a filter. Changing the request encoding does not work in a servlet!- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_ENCODINGThe default encoding is UTF-8static booleanDEFAULT_FORCE_ENCODINGBy default the encoding is not enforced.static StringINITPARAM_ENCODINGName of the init parameter for the encodingstatic StringINITPARAM_FORCE_ENCODINGName of the init parameter to force setting the request and response encodingstatic StringINITPARAM_FORCE_REQUEST_ENCODINGName of the init parameter to force setting the request encodingstatic StringINITPARAM_FORCE_RESPONSE_ENCODINGName of the init parameter to force setting the response encoding
-
Constructor Summary
Constructors Constructor Description CharacterEncodingFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddoHttpFilter(jakarta.servlet.http.HttpServletRequest aRequest, jakarta.servlet.http.HttpServletResponse aResponse, jakarta.servlet.FilterChain aChain)Implement this main filtering method in subclasses.StringgetEncoding()voidinit()Init this filterbooleanisForceRequestEncoding()booleanisForceResponseEncoding()voidsetEncoding(String sEncoding)voidsetForceEncoding(boolean bForce)voidsetForceRequestEncoding(boolean bForce)voidsetForceResponseEncoding(boolean bForce)-
Methods inherited from class com.helger.servlet.filter.AbstractHttpServletFilter
doFilter
-
Methods inherited from class com.helger.servlet.filter.AbstractServletFilter
destroy, getFilterConfig, init, toString
-
-
-
-
Field Detail
-
INITPARAM_ENCODING
public static final String INITPARAM_ENCODING
Name of the init parameter for the encoding- See Also:
- Constant Field Values
-
INITPARAM_FORCE_REQUEST_ENCODING
public static final String INITPARAM_FORCE_REQUEST_ENCODING
Name of the init parameter to force setting the request encoding- See Also:
- Constant Field Values
-
INITPARAM_FORCE_RESPONSE_ENCODING
public static final String INITPARAM_FORCE_RESPONSE_ENCODING
Name of the init parameter to force setting the response encoding- See Also:
- Constant Field Values
-
INITPARAM_FORCE_ENCODING
public static final String INITPARAM_FORCE_ENCODING
Name of the init parameter to force setting the request and response encoding- See Also:
- Constant Field Values
-
DEFAULT_ENCODING
public static final String DEFAULT_ENCODING
The default encoding is UTF-8
-
DEFAULT_FORCE_ENCODING
public static final boolean DEFAULT_FORCE_ENCODING
By default the encoding is not enforced.- See Also:
- Constant Field Values
-
-
Method Detail
-
getEncoding
@Nonnull @Nonempty public final String getEncoding()
- Returns:
- The encoding to be used by this filter. Neither
nullnor empty.
-
isForceRequestEncoding
public final boolean isForceRequestEncoding()
-
setForceRequestEncoding
public final void setForceRequestEncoding(boolean bForce)
-
isForceResponseEncoding
public final boolean isForceResponseEncoding()
-
setForceResponseEncoding
public final void setForceResponseEncoding(boolean bForce)
-
setForceEncoding
public final void setForceEncoding(boolean bForce)
-
init
public void init() throws jakarta.servlet.ServletExceptionDescription copied from class:AbstractServletFilterInit this filter- Overrides:
initin classAbstractServletFilter- Throws:
jakarta.servlet.ServletException- In case of an error
-
doHttpFilter
public void doHttpFilter(@Nonnull jakarta.servlet.http.HttpServletRequest aRequest, @Nonnull jakarta.servlet.http.HttpServletResponse aResponse, @Nonnull jakarta.servlet.FilterChain aChain) throws IOException, jakarta.servlet.ServletException
Description copied from class:AbstractHttpServletFilterImplement this main filtering method in subclasses.- Specified by:
doHttpFilterin classAbstractHttpServletFilter- Parameters:
aRequest- The HTTP request. Nevernull.aResponse- The HTTP response. Nevernull.aChain- The further filter chain.- Throws:
IOException- In case of an IO errorjakarta.servlet.ServletException- For non IO errors
-
-