Websphere Application Server 8.5 上 Web 应用程序 运行 中的字符编码

Character encoding in web applicaion running on Websphere Application Server 8.5

我在创建的 IBM WebSphere Application 中遇到西里尔符号表示(它们看起来像“0B0;1O”)的问题。

所以我使用 WebSphere 8.5 (Unix Red Hat) 并且应用程序是一个 java-servlet,它侦听 HTTP POST 请求。

WebSphere 上的 JVM 属性是:

我检查了文件 encoding.properties 并将编码设置为 UTF8。我通过以下代码以 UTF8 发送对我的应用程序的请求:

   HttpURLConnection connection = (HttpURLConnection)url.openConnection();
   connection.setRequestMethod("POST"); 
   connection.setRequestProperty("Accept-Charset", "UTF-8");
   connection.setRequestProperty("Content-Type", "text/plain; charset=UTF-8");
   connection.setRequestProperty("Content-Length", Integer.toString(resultXML.getBytes().length));
   connection.setUseCaches (false);
   connection.setDoInput(true);
   connection.setDoOutput(true);

   //Send request
   DataOutputStream wr = new DataOutputStream (
             connection.getOutputStream ());
  // BufferedWriter br = new BufferedWriter(new OutputStreamWriter(wr, "UTF-8"));
   BufferedWriter br1 = new BufferedWriter(new OutputStreamWriter(wr, Charset.forName("UTF-8")));
   br1.write(resultXML);
   br1.close();
   wr.flush ();
   wr.close ();

   //Get Response
   BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
   String line;
   while ((line = rd.readLine()) != null) {
      System.out.println(line);
   }
   rd.close();

在应用程序 HTTP 请求处理程序中,首先我通过以下方式设置编码:

        response.setCharacterEncoding("UTF-8");

        request.setCharacterEncoding("UTF-8");

但是请求和响应中的所有西里尔符号看起来都不正确,当应用程序将它们放入 Oracle DB 或只是响应这些符号时,这些符号有错误的视图。

有问题请帮忙解决!

此问题已解决。

已正确处理请求西里尔符号,问题出在响应上。以下代码有帮助。

        PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF8"), true);
        for (int i = 0; i < result.length(); i++)
        {
            out.print(result.charAt(i));
        }

        out.flush();