调用别人的rest接口,本地测试返回不乱码,运行在tomcat上会出现部分中文乱码,跪求大神

private ResResult getResResult(HttpURLConnection httpURLConnection, String policyStatusJson)
{
BufferedReader bufferedReader = null;
DataOutputStream dataOutputStream = null;
ResResult res = null;
try
{
if (policyStatusJson != null)
{
dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream());
dataOutputStream.write(policyStatusJson.getBytes());
}
bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
StringBuffer resultBuf = new StringBuffer("");
String line = null;
while ((line = bufferedReader.readLine()) != null) {
line = new String(line.getBytes(), "utf-8");
resultBuf.append(line);
}
res = (ResResult)new Gson().fromJson(resultBuf.toString(), ResResult.class);
httpURLConnection.disconnect();

  return res;
}
catch (IOException e)
{
  e.printStackTrace();
}
finally
{
  try
  {
    if (bufferedReader != null) {
      bufferedReader.close();
    }
    if (dataOutputStream != null) {
      dataOutputStream.close();
    }
  }
  catch (IOException e)
  {
    e.printStackTrace();
  }
}
return res;

}

==========本地测试结果============

最新更新时间:2018-10-15 16:48:29.31 内容是:保单状态1

===========tomcat服务运行结果==========

:�?新更新时间:2018-10-15 16:48:29.31 内容是:保单状�??1;

6个回答

HttpURLConnection设置Content-Type了吗

weixin_36165756
weixin_36165756 都配置了
接近 2 年之前 回复

tomcat 配置文件中可以配置编码 去conf中配置即可

weixin_36165756
weixin_36165756 我也试了,你说的具体是怎么配置
接近 2 年之前 回复

很明显的 直接找TOMCAT 啊~~~~~~

数据库中配置utf-8了吗?

tomcat server.xml的编码格式配置了吗 URIEncoding="UTF-8"

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问