Websphere 8.5.5 UTF-8编码问题 [英] Websphere 8.5.5 UTF-8 encoding issue
问题描述
我在 Websphere 8.5.5 上的应用程序有问题.这是一个用于发送电子邮件的Spring Rest应用程序.在我的服务中,我收到邮件详细信息,然后使用spring将其转发给收件人.它工作正常,但是当我尝试发送非ASCII字符的消息时,消息以特殊字符替换为问号. UTF-8 编码无效.在我的电脑上,该应用程序在Liberty Profile服务器上运行,最初也无法正常运行.我在问题上进行了搜索,发现spring需要一个过滤器来解释特殊字符,因此我将这些行添加到了 web.xml
I have a problem with my application on 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. 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. The UTF-8 encoding doesn't work. In my pc the application runs on Liberty Profile server and initially it doesn't work either. 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
<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可以正常工作,但是当我在Websphere上部署应用程序时却不能.
On Liberty works fine but when I deploy the app on Websphere it doesn't.
我尝试使用String构造函数直接将消息转换为utf-8:
I tried to directly translate the message in utf-8 with the String constructor:
new String(byteArray, "UTF-8")
,同样的事情发生了.它适用于自由,但不适用于Websphere. 然后,我发现您可以通过添加以下JVM参数来强制WebSphere使用 UTF-8 :
and the same thing happens. It works on liberty but it doesn't on Websphere. Then I found that you can force WebSphere to use UTF-8 by adding these JVM Arguments:
-Dclient.encoding.override=UTF-8
-Dfile.encoding=UTF-8
就像在这个答案中解释的那样: websphere上的字符编码问题
like explained in this answer: Character encoding issues on 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.
这是运行WAS的linux机器中的locale命令的输出:
This is the output of locale command in linux machine where WAS run:
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.
任何帮助将不胜感激.
推荐答案
位于<PROFILE_ROOT>/properties
的encoding.properties
文件是另一个包含编码设置的位置.默认值(英语)为en=ISO-8859-1
.将其更新为en=UTF-8
并重新启动服务器.
The encoding.properties
file located at <PROFILE_ROOT>/properties
is one more location that contains encoding settings. The default value (for English) is en=ISO-8859-1
. Update this to en=UTF-8
and restart the server.
这篇关于Websphere 8.5.5 UTF-8编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!