【应用服务 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 encodinghttps://stackoverflow.com/questions/361975/setting-the-default-java-character-encoding

 

 

posted @   路边两盏灯  阅读(383)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示