In my application also used the 'struts.i18.encoding=UTF-8' but I had
the same problem. But I found a way to get it to work.
This way you are only telling struts that has to use UTF-8. But you
also need to tell to your Applications Container
(Tomcat for example) that you want UTF-8.
1. Set the URI encoding of Tomcat's server.xml configuration file. Set
URIEncoding="UTF-8" in your http/https connectors:
<!-- Define a non-SSL HTTP/1.1 Connector on port 80 -->
<Connector URIEncoding="UTF-8" acceptCount="100" connectionTimeout="20000"
disableUploadTimeout="true" enableLookups="false"
maxHttpHeaderSize="8192" maxSpareThreads="75" maxThreads="150"
minSpareThreads="25" port="80" redirectPort="443"/>
2. Set a custom filter to configure POST requests use UTF-8:
<!-- To get POST requests as UTF-8 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>path.to.your.filter.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Tomcat already comes with such an example filter of SetCharacterEncodingFilter.
3. Also in my application's web.xml I have set that JSPs use UTF-8 as a default:
<jsp-config>
<!-- UTF-8 as the default JSP encoding -->
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
4. In every JSP you I have the following typical <meta> tag inside <head>:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
I hope it will help.
Cristian.
On Fri, Nov 20, 2009 at 10:14 AM, carl ballantyne
<[email protected]> wrote:
> Hi Guys,
>
> I have an app with form fields and when submitting them to my Struts 2
> actions the values are getting garbled. For example "espaƱa" becomes
> "espa?".
>
> I think the problem is with Struts because when I create a basic jsp page
> and submit back to itself and display the form field - it works fine.
>
> I have tried setting struts.i18n.encoding=UTF-8 in the struts.properties
> file and the struts.xml file to no avail. Has anyone used this with success?
> I have searched the forums and it seems to me that people have to resort to
> custom filters to workaround the problem.
>
> Cheers,
> Carl.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
--
GPG Key-ID: 0x564903FA - JID: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]