Form Encoding Problems on GRAILS 2.0

2019-04-02 10:33发布

问题:

I have an Grails application that is configured everywhere to function as UTF-8. While running a debug version, headers say Content-Type:text/html;charset=utf-8, and meta tags agree. Browser identified page as UTF-8 and shows characters correctly.

When posting a form, the browser correctly sends it encoded as UTF-8. When reading the data via params.paramname, however, the data looks garbled; maçã becomes maçã.

Upon further inspection, it seems the form is sending UTF-8 data, but Grails seem to try and read it as if it was ISO-8859-1. Setting accept-charset="ISO-8859-1" on the form confirms this problem, as it fixes the problem.

I also have this on applicationContext.xml:

<bean id="characterEncodingFilter" class="org.springframework.web.filter.CharacterEncodingFilter">
    <property name="encoding">
        <value>utf-8</value>
    </property>
    <property name="forceEncoding">
        <value>true</value>
    </property>
</bean>

Is there an solution for this besides adding accept-charset="ISO-8859-1" to all forms in the application?

Thanks.

回答1:

I think you encounter the same problem as in Grails request parameters encoding issue in Tomcat - either Burt's answer or comments to it should help.