问题
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 works fine but when I deploy the app on Websphere it doesn't.
I tried to directly translate the message in utf-8 with the String constructor:
new String(byteArray, "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
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.
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.
Any help would be appreciated.
回答1:
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.
来源:https://stackoverflow.com/questions/38399270/websphere-8-5-5-utf-8-encoding-issue