0
点赞
收藏
分享

微信扫一扫

【应用服务 App Service】App Service 中部署Java应用中文乱码现象

问题情形

有时候部署在 Azure  App Service的 Java应用会出现乱码

详细日志

无 

问题原因

因为 App Service默认的编码为gbk,所以在显示页面或传递中文字符时就会出现乱码。

解决方案

部署在App Service的Java应用,都会在site/wwwroot 文件夹下创建 web.config 文件。需要在environmentVariable中添加-Dfile.encoding=UTF-8。 

<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%AZURE_TOMCAT85_HOME%\bin\startup.bat" arguments="">
<environmentVariables>
<environmentVariable name="JAVA_OPTS" value="-Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8" />
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>

 

参考资料

 

如何解决 Java Web 应用在向第三方服务传送中文时出现乱码的问题: ​​https://docs.azure.cn/zh-cn/articles/azure-operations-guide/app-service-web/aog-app-service-web-java-qa-solve-messy-code-during-sending-chinese-characters-to-third-party-services​​

​​Setting the default Java character encoding​​​: ​​https://stackoverflow.com/questions/361975/setting-the-default-java-character-encoding​​

 

 

当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!



举报

相关推荐

0 条评论