struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Li Ying <>
Subject Re: Unicode Encoding request parameters
Date Sun, 25 Sep 2011 04:27:07 GMT
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 [], 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 <>:
> 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.
> Z.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message