简体   繁体   English

Websphere 8.5.5 UTF-8 编码问题

[英]Websphere 8.5.5 UTF-8 encoding issue

I have a problem with my application on Websphere 8.5.5 .我在Websphere 8.5.5上的应用程序有问题。 It's a spring rest application that is used to send email.这是一个用于发送电子邮件的弹簧休息应用程序。 In my service I receive the mail details and I use spring to forward it to the receivers.在我的服务中,我收到邮件详细信息,并使用 spring 将其转发给接收者。 It works fine but when I try to send messages with non ascii character the message arrives with the special characters replaced by a question mark.它工作正常,但是当我尝试使用非 ascii 字符发送消息时,消息到达时将特殊字符替换为问号。 The UTF-8 encoding doesn't work. UTF-8编码不起作用。 In my pc the application runs on Liberty Profile server and initially it doesn't work either.在我的电脑中,应用程序在 Liberty Profile 服务器上运行,最初它也不起作用。 I googled the problem and found that spring needs a filter to interpret the special characters, so I added this lines to my web.xml我用谷歌搜索了这个问题,发现 spring 需要一个过滤器来解释特殊字符,所以我将这行添加到我的web.xml

<filter>
      <filter-name>CharacterEncodingFilter</filter-name>
      <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
      <init-param>
          <param-name>encoding</param-name>
          <param-value>UTF-8</param-value>
      </init-param>
  </filter>
  <filter-mapping>
       <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/</url-pattern>
  </filter-mapping>

On Liberty works fine but when I deploy the app on Websphere it doesn't.在 Liberty 上工作正常,但是当我在 Websphere 上部署应用程序时却没有。

I tried to directly translate the message in utf-8 with the String constructor:我尝试使用 String 构造函数直接翻译 utf-8 中的消息:

new String(byteArray, "UTF-8")

and the same thing happens.同样的事情发生了。 It works on liberty but it doesn't on Websphere.它适用于自由,但不适用于 Websphere。 Then I found that you can force WebSphere to use UTF-8 by adding these JVM Arguments:然后我发现您可以通过添加这些 JVM 参数来强制 WebSphere 使用UTF-8

-Dclient.encoding.override=UTF-8
-Dfile.encoding=UTF-8

like explained in this answer: Character encoding issues on websphere就像在这个答案中解释的那样: Websphere 上的字符编码问题

I set the parameters on my server and restart like explained in many guides I found on the internet, but obviously it didn't work.我在我的服务器上设置了参数并按照我在互联网上找到的许多指南中的解释重新启动,但显然它不起作用。

This is the output of locale command in linux machine where WAS run:这是运行 WAS 的 linux 机器中 locale 命令的输出:

LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

I'am stuck and do not know what else to try.我被卡住了,不知道还能尝试什么。

Any help would be appreciated.任何帮助将不胜感激。

The encoding.properties file located at <PROFILE_ROOT>/properties is one more location that contains encoding settings.位于<PROFILE_ROOT>/propertiesencoding.properties文件是另一个包含编码设置的位置。 The default value (for English) is en=ISO-8859-1 .默认值(英语)是en=ISO-8859-1 Update this to en=UTF-8 and restart the server.将其更新为en=UTF-8并重新启动服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM