I had a problem with the encoding encoding in my web application (JSF 1.2, Spring and Tomcat 7) and I ended up with ideas on what to test to see where this is happening.
Whenever I send something like "çã" I get "ÃÃÃÃ": this means that my POSTed data as UTF-8 is converted to ISO-8859-1 somewhere in the life of the JSF cycle.
I know that the wrong conversion is UTF-8 according to ISO-8859-1, which leads to the same conclusion:
System.out.println(new String("çã".getBytes("UTF-8"), "ISO-8859-1"));
I believe that the wrong conversion is somewhere in the JSF life cycle (maybe earlier?), Because I configured the validator in my MB:
public void debugValidator(FacesContext context, UIComponent component, Object object) throws ValidationException { System.out.println("debug validator:"); System.out.println(object); System.out.println("\n"); throw new ValidationException("DEBUG: " + object.toString()); }
and his message is returned as: "DEBUG: çà £"
- I have on all my .xhtml pages the first line as
<?xml version="1.0" encoding="UTF-8"?> . - I use Facelets, which according to the BalusC article uses UTF-8 by default
- Therefore, I did not need this, but I still set up Spring
CharacterEncodingFilter in my web.xml to set the request character encoding to UTF-8. - I put
URIEncoding="UTF-8" in the Tomcat server.xml file to guarantee - This is not my browser error, it prints the same in the console, and my environment is UTF-8 .
Do you have any idea what else to check? What could be my wrong assumption?
Thanks in advance!
source share