0

How do I configure SpringMVC's annotation messages encoding? For example, I annotated a field of the form to be validated like this:

@NotEmpty(message = "ъ")

But when the error occurs, it is encoded in a wrong charset. Encoding filter in web.xml is enabled and *.java files are UTF-8. Tomcat's Connector in server.xml is configured to deal with UTF-8.

Max
  • 389
  • 3
  • 6
  • Java files are in UTF8, but have you configured the compiler to make it read Java files as UTF8? http://stackoverflow.com/questions/1726174/how-to-compile-a-java-source-file-which-is-encoded-as-utf-8 – JB Nizet Nov 15 '14 at 13:46

1 Answers1

0

If you know the original charset, you can try to convert the original string to UTF. For example:

public static String convertFromISO88591ToUTF8( String original )
{
    String converted = original;
    try
    {
        byte[] iso88591Bytes = original.getBytes( "ISO-8859-1" );
        converted = new String( iso88591Bytes, "UTF8" );
    }
    catch ( UnsupportedEncodingException e )
    {
        e.printStackTrace();
    }
    return converted;
}

Actually, I've been using this same method (without changes) on the back-end even regardless the encoding on the front-end and it has been working fine. However, I didn't make a systematic test for all encoding types.

I hope it helps.

Almir Campos
  • 2,833
  • 1
  • 30
  • 26