org.springframework.web.filter
public class: CharacterEncodingFilter [javadoc |
source]
java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
org.springframework.web.filter.CharacterEncodingFilter
All Implemented Interfaces:
Filter, DisposableBean, BeanNameAware, InitializingBean, ServletContextAware
Servlet 2.3/2.4 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 on Servlet 2.4+ containers (although
this will usually be overridden by a full content type set in the view).
Also see:
- setEncoding
- setForceEncoding
- javax.servlet.http.HttpServletRequest#setCharacterEncoding
- javax.servlet.http.HttpServletResponse#setCharacterEncoding
- author:
Juergen - Hoeller
- since:
15.03.2004 -
| Methods from org.springframework.web.filter.GenericFilterBean: |
|---|
|
addRequiredProperty, afterPropertiesSet, destroy, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setServletContext |
| Method from org.springframework.web.filter.CharacterEncodingFilter Detail: |
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain) throws IOException, ServletException {
if (this.encoding != null && (this.forceEncoding || request.getCharacterEncoding() == null)) {
request.setCharacterEncoding(this.encoding);
if (this.forceEncoding && responseSetCharacterEncodingAvailable) {
response.setCharacterEncoding(this.encoding);
}
}
filterChain.doFilter(request, response);
}
|
public void setEncoding(String encoding) {
this.encoding = encoding;
}
|
public void setForceEncoding(boolean forceEncoding) {
this.forceEncoding = forceEncoding;
}
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.
Note that the response encoding will only be set on Servlet 2.4+
containers, since Servlet 2.3 did not provide a facility for setting
a default response encoding. |