Here are some comments. I have tried it on Firefox 4.0.1 and IE 8.0 64 bit. My PC is running 64bit Windows7 and Tomcat 7.0. JDK is 1.6.0_24 and I have used the system property JAVA_TOOL_OPTIONS set to -Dfile.encoding=UTF8. Instead of <form> tag I have tried also <form method="get" accept-charset="UTF-8"> and also <form method="post" accept-charset="UTF-8">. I have also tried the response.setContentType("text/html; charset=UTF-8") and response.setCharacterEncoding("UTF-8"). But nothing helped.
Let me try to clarify all of that. When you say you want to "send" those characters from a JSP, you are actually talking about the HTML generated by that JSP. You want that HTML to send a request containing those characters. You aren't saying you want the JSP to generate some HTML which contains those characters. Right so far?
Then you have something about "my PC". That's the PC which is running your server, correct? Looking at the PC where the browsers are located isn't going to be relevant. Neither are the browsers, in fact.
So to summarize, if I understand correctly, you want your browser to send a request which contains non-ASCII characters and you want that request to be received correctly in your server. But what is happening instead is, despite your best attempts to configure everything to use UTF-8, something is causing the request to be treated as if it's in some other charset.
Well, first of all this all has nothing to do with the fact that your HTML was generated by a JSP. So the JSP forum isn't the right place for the question. So since your server is Tomcat, I'm going to move it to the Tomcat forum.
I was just working with this exact question the day before yesterday.So I can tell you the answer for Websphere, but not for Tomcat. But essentially you have to tell Tomcat to treat requests as if their charset was UTF-8. It appears that you tried to set Tomcat's file.encoding system property to UTF-8... did that work? You posted a JSP which answers that question but didn't tell us the answer.
Hi thanks for reply. Unfortunately it did not help. Anyway your summary was exactly right - simply I want to send non-ascii characters via HTML generated using JSP to server. I have changed the configuration in server.xml as you suggested: <Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" /> . My server runs on port 8081. Just to be exactly precise the body of my page now looks like this:
String s1 = String.valueOf(request.getParameter("first"));
<%= System.getProperty("file.encoding") %>
The response for <%= System.getProperty("file.encoding") %> is UTF-8. I have tried it also on JBoss 5.0.1 with the same problem.
What is very interesting the the whole thing works well when I (on JBoss) have similar example but the request.getParameter("first") is managed via getters/setters using Java Beans. When you deploy the JSP page into your server does it work correctly with non-ascii characters?
It actually helped - forget to restart servers. Thanks a lot! Anyway it works only with <form method="get"> but does not work with <form method="post"> . I have encountered similar problem on some forum but was not solved as well. Anyway I am glad that get method works :-)
"GET" sends data as part of the URL. The URL is parsed by the server. That's why server configuration settings can be important.
"POST" sends data as part of the content. Content has a MIME type and encoding. So the place to set character set (code page) information would be on the HTML POST element itself. I think the "ACCEPT-CHARSET" attribute is probably the one you want.
Sources may include data from the Fakebook Research Foundation with support from Gargle University