Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
I'm sending UTF8 encoded strings across http to the PE server but they're getting mangled into unusable strings.
For example:
<!-- 中,您将学习如何使用 -->
becomes a garbled string, either:
<!-- 中 xEFxBC?XE6?XA8XE5XB0学习xE5xA6xBD?Xa* -->
or
<!-- ????????????? -->
depending on how I write to code on the server.
The internet/Java sites suggest a variety of fixes, none are working.
Some suggest adding enctyle or <meta> to my html form:
<form method="POST" action="http://132.253.204.201:8080/e3/servlet/e3" enctype="application/x-www-form-urlencoded; charset=utf-8">
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
These don't help.
Some suggest different combinations of ways to read the object at the server, like:
new FileOutputStream("D:\\UTF8Output_2.txt"), "UTF-8");
or
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(request_XML_filename),"UTF8"));
or
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(request_XML_filename),"UTF-8"));
None of these work.
Has anyone tacked this yet?
Solved! Go to Solution.
Found the right combination:
Read the E3ApplicationRequest object with:
final String req_XML_string_2 = new String(req.getParameter("p2").getBytes("iso-8859-1"), "UTF-8"); |
and write the file with:
Writer writer_2 = new OutputStreamWriter(new FileOutputStream("D:\\UTF8Output_2.txt"), "UTF-8");
BufferedWriter fout_2 = new BufferedWriter(writer_2);
fout_2.write(req_XML_string_2);
fout_2.close();
Found the right combination:
Read the E3ApplicationRequest object with:
final String req_XML_string_2 = new String(req.getParameter("p2").getBytes("iso-8859-1"), "UTF-8"); |
and write the file with:
Writer writer_2 = new OutputStreamWriter(new FileOutputStream("D:\\UTF8Output_2.txt"), "UTF-8");
BufferedWriter fout_2 = new BufferedWriter(writer_2);
fout_2.write(req_XML_string_2);
fout_2.close();