I have a JSP
that contains an html form which posts back to itself.
This form needs to accept international text, German and Japanese for example. So, I have used a page directive to set the contentType of the JSP to "text/html; charset=UTF-8" and characterEncoding to "UTF8". I'm also calling request.setCharacterEncoding("UTF8") when handling the post-back before any other method is called on the request object. This being deployed to Tomcat
The problem I'm having is that the request parameters are still being read as Latin-1.
(Meaning that if I enter the following German text into the html form,
"Schr�der nennt R�cktrittsger�chte �wildeste Spekulation�"
when I call request.getParameter it returns,
"Schr��der nennt R��cktrittsger��chte ��wildeste Spekulation��"
I've tried setting every character encoding/content type related setting on the JSP, the request, the response, and Tomcat that I can dig up but with no success. After becoming completely frustrated with the problem, I created a servlet
to handle the post, as I should have to begin with, just to see what would happen. To my surprise, after copying the exact same code from my JSP into the servlet's doPost and having the form post to the servlet, the request parameters come across perfectly fine as UTF-8 encoded Strings.
Obviously, I can just have my forms post to a servlet or I can explicity convert the strings from Latin-1 to UTF-8. But I would really like to understand why the JSP does not handle character encoding for request parameters in the same way that the servlet does.
Is this a known issue? If anyone has any insight or ideas they would be greatly appreciated. The code for both the JSP and the servlet is posted below, along with the console output.
Request Encoding: UTF8
Text Value: Schr�der nennt R�cktrittsger�chte �wildeste Spekulation�
Text From Latin1 to UTF8: Schr.der nennt R.cktrittsger.chte .wildeste Spekulation.
Input Stream Encoding: UTF8
Output Stream Encoding: UTF8
System File Encoding Property: UTF-8
[BSouther: Added UBB CODE tags
[ April 25, 2007: Message edited by: Ben Souther ]