Reputation: 2321
I'm working on a web app using JSF 2 and Tomcat 6. I am getting the following exception: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 3-byte UTF-8 sequence
when I try to load the page in question. I have accented Spanish characters in the display text, and I've figured out that they are causing the exception. For example, <p>ñ</p>
causes an error, but <p>n</p>
works fine. Note that this example text is hard coded and wrapped in a <ui:define>
tag.
I'll also note that in the client .xhtml file (the page in question) uses a template. The template file has the <?xml version="1.0" encoding="UTF-8"?>
declaration. Any suggestions on what could be the problem? I've searched the internet and SO, and there are a lot of questions out there concerning this specific exception, but most don't deal with JSF, but involve other details that influence what might be the cause of the problem. Thanks for your suggestions.
Upvotes: 0
Views: 2003
Reputation: 2321
Upon further investigation (trial and error), I got it to work by changing a setting in Eclipse. I didn't mention in the question that I was using Eclipse, out of ignorance of the issue I guess...hindsight. Anyway, here's what I did that made my page display the text with Spanish accented characters: in Eclipse, under Preferences/General/Workspace
, there is an option for "Text file encoding" that was set to the default of "Cp1252". I changed this to use UTF-8, and it worked. I also changed an "Encoding" setting to use UTF-8 under each of the folowing: Preferences/Web/CSS Files
, Preferences/Web/HTML Files
, and Preferences/XML/XML Files
. I had changed those (without successfully displaying the accented characters) before finally finding the "General/Workspace" setting, so I'm not sure whether they had an impact or not.
Upvotes: 3