You don't need an extra-filter.

The S2 default encoding is UTF-8.

The code of S2 filter is:

public void doFilter(......) {
prepare.setEncodingAndLocale(request, response);

and the code of PrepareOperations is :
public void setEncodingAndLocale(HttpServletRequest request,
HttpServletResponse response) {
dispatcher.prepare(request, response);

and the code of Dispatcher is:

public void prepare(HttpServletRequest request,
HttpServletResponse response) {
String encoding = null;
if (defaultEncoding != null) {
encoding = defaultEncoding;


if (encoding != null) {
try {
} catch (Exception e) {
LOG.error("Error setting character encoding to '" +
encoding + "' - ignoring.", e);

and the code of property [defaultEncoding] is:
public void setDefaultEncoding(String val) {
defaultEncoding = val;

the value of [defaultEncoding] will be injected by the property
which is "struts.i18n.encoding".

And this property is defined in [struts-default.properties], which's
value is [UTF-8]:

You can read the following S2 documents:

If you want to change the default encoding, you can change the value
of property [struts.i18n.encoding].

By the way.
This encoding setting only works for the POST params (which are part
of the form element).
For the GET params(which are part of URL), the encoding can not be set
in J2EE context.
It will be parsed by the J2EE container (e.g: Tomcat) BEFORE your code
is executed.

In this case, the solution are:
(1)do not use non-ascii chars in URL params
(2)change the Tomcat setting about url param encoding: [URIEncoding].
It is descriped in this document:

2011/9/20 Zoran Avtarovski <zoran@sparecreative.com>:
We have a struts2 multilingual web app that requires request parameters be
encoded as Unicode (UTF-8).

In order to get the POST parameters to work we had to implement a character
encoding filter to encode all HTML parameters as UTF-8.

I'd like to know if it's possible to do the encoding via S2 and avoid the
use of another filter. We'e set the struts.i18n.encoding property to UTF-8
and I don't know what else to do.

As always I'd appreciate any suggestions you guys might have.


To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

Search Discussions

Discussion Posts


Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 2 | next ›

2 users in discussion

Zoran Avtarovski: 1 post Li Ying: 1 post



site design / logo © 2016 Grokbase