I got a very strange problem here.
I need to read data from SQL Server (ver. 2016). A name like O'Neal
.
When I load the String in my IDE/TextEditor, O'Neal
could be read correctly as O'Neal
.
But when I package my program as jar or war file, O'Neal
is loaded like this O��Neal
.
I have no idea how does this happend. Any suggestion would be appreciated. Thanks.
I got a very strange problem here.
I need to read data from SQL Server (ver. 2016). A name like O'Neal
.
When I load the String in my IDE/TextEditor, O'Neal
could be read correctly as O'Neal
.
But when I package my program as jar or war file, O'Neal
is loaded like this O Neal
.
I have no idea how does this happend. Any suggestion would be appreciated. Thanks.
Refer to this question
Like @Arvind said, it runs correctly in IDE/Editor, because it's already encoded as UTF-8.
However, the jar or tomcat isn't, so we have to make sure it runs with encoding UTF-8.
> java -Dfile.encoding="UTF-8" -jar test.jar
However this command couldn't run in PowerShell, I don't know why it's another issue.
{pathToTomcat}/bin
, open catalina.bat
with editor. add set "JAVA_OPTS=%JAVA_OPTS% -Djavax.servlet.request.encoding=UTF-8 -Dfile.encoding=UTF-8"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.