Example filter that sets the character encoding to be used in parsing the incoming request, either unconditionally or only if the client did not specify a character encoding. Configuration of this filter is based on the following initialization parameters:
ignore initialization parameter. This parameter is required, so there is no
default.selectEncoding() method is set. If set to "false, selectEncoding() is
called only if the client has not already specified an encoding. By default, this parameter is set
to "false".
Although this filter can be used unchanged, it is also easy to subclass it and make the selectEncoding()
method more intelligent about what encoding to choose, based on characteristics of the incoming request (such as the
values of the Accept-Language and User-Agent headers, or a value stashed in the current
user's session.
| Modifier and Type | Field and Description |
|---|---|
| private String | encoding
The default character encoding to set for requests that pass through this filter. |
| private boolean | ignore
Should a character encoding specified by the client be ignored? |
| private final Log |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | doFilter(ServletRequest
The servlet request we are processing request, ServletResponse The servlet response we are creating response, FilterChain The filter chain we are processing chain)Implements jakarta. Select and set (if specified) the character encoding to be used to interpret request parameters for this request. |
| public String | |
| protected Log | |
| public boolean | |
| protected String | Returns: the encoding that was configuredThe servlet request we are processing request)Select an appropriate character encoding to be used, based on the characteristics of the current request and/or filter initialization parameters. |
| public void | |
| public void |
| encoding | back to summary |
|---|---|
| private String encoding The default character encoding to set for requests that pass through this filter. | |
| ignore | back to summary |
|---|---|
| private boolean ignore Should a character encoding specified by the client be ignored? | |
| log | back to summary |
|---|---|
| private final Log log | |
| SetCharacterEncodingFilter | back to summary |
|---|---|
| public SetCharacterEncodingFilter() | |
| doFilter | back to summary |
|---|---|
| public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException Implements jakarta. Select and set (if specified) the character encoding to be used to interpret request parameters for this request.
| |
| getEncoding | back to summary |
|---|---|
| public String getEncoding() | |
| getLogger | back to summary |
|---|---|
| protected Log getLogger() Implements abstract org.
| |
| isIgnore | back to summary |
|---|---|
| public boolean isIgnore() | |
| selectEncoding | back to summary |
|---|---|
| protected String selectEncoding(ServletRequest request) Select an appropriate character encoding to be used, based on the characteristics of the current request and/or
filter initialization parameters. If no character encoding should be set, return The default implementation unconditionally returns the value configured by the encoding initialization parameter for this filter.
| |
| setEncoding | back to summary |
|---|---|
| public void setEncoding(String encoding) | |
| setIgnore | back to summary |
|---|---|
| public void setIgnore(boolean ignore) | |