当前位置:网站首页>Solution to using json.tojsonstring to display question marks in Chinese in Servlet
Solution to using json.tojsonstring to display question marks in Chinese in Servlet
2022-07-28 12:54:00 【it_ hao528】
problem :
stay Servlet Use in fastjson Will pass through
JSON.toJSONString()
Method to convert the object to JSON After the string , stay IDEA The converted data printed in Chinese is normal , But the client and web Among the data received , Chinese is displayed as a question mark ?. What's going on here ?
Problem analysis :
I believe what I thought at the first time was that there was a problem with transcoding . So in which link did the transcoding go wrong ?
Because in IDEA The console prints the converted JSON The string is displayed normally , You may feel that the returned data should also be normal , But in the use of
response.getWriter().write(jsonString);
After outputting the data to the client , The data received by the client is indeed the question mark displayed in Chinese ?. So at this time, we should consider whether we are using
response.getWriter().write(jsonString);
There is something wrong with the output . In fact, the problem lies here . So how to solve it ?
resolvent :
After analyzing the problem , Roughly determine the location of the problem , Then it's easy to solve .
Here are two solutions .
Scheme 1 :
We know that Chinese garbled code may appear when the client transmits parameters to the background , The corresponding solution is right request Deal with it accordingly , For example, deal with post The Chinese garbled code of request parameters can be set as follows :
request.setCharacterEncoding("UTF-8");
Sending data to the client uses response, that response Is there such a method ? The answer is clearly yes , So you can set :
response.setCharacterEncoding("UTF-8");
To solve the problem of Chinese garbled code when sending data to the client .
Option two :
In fact, there is another way to solve , Is set response Of contentType as follows :
response.setContentType("text/html;charset=utf-8");
It can also solve the problem of Chinese garbled code when sending data to the client .
Last , I hope I can help code friends in need .
边栏推荐
- leetcode 376. Wiggle Subsequence
- 04 pyechars 地理图表(示例代码+效果图)
- 力扣315计算右侧小于当前元素的个数
- STM32F103 几个特殊引脚做普通io使用注意事项以及备份寄存器丢失数据问题1,2
- Which big model is better? Openbmb releases bmlist to give you the answer!
- FlexPro软件:生产、研究和开发中的测量数据分析
- 利用依赖包直接实现分页、SQL语句
- Four authentic postures after suffering and trauma, Zizek
- LeetCode84 柱状图中最大的矩形
- Fundamentals of machine learning - principal component analysis pca-16
猜你喜欢

04 pyechars geographic chart (example code + effect diagram)

Science heavyweight: AI design protein has made another breakthrough, and it can design specific functional proteins

单调栈Monotonic Stack

LeetCode94. 二叉树的中序遍历

01 introduction to pyechars features, version and installation

Review the IO stream again, and have an in-depth understanding of serialization and deserialization

Application and download of dart 3D radiative transfer model

Machine learning practice - integrated learning-23

SuperMap iclient3d for webgl to realize floating thermal map

Distributed session solution
随机推荐
Multiple items on a computer share a public-private key pair to pull the Gerrit server code
上位机和三菱FN2x通信实例
Fundamentals of machine learning - principal component analysis pca-16
Leetcode206 reverse linked list
试用copilot过程中问题解决
Redefinition problem of defining int i variable in C for loop
Block reversal (summer vacation daily question 7)
Summary: idea problem record
New Oriental's single quarter revenue was 524million US dollars, a year-on-year decrease of 56.8%, and 925 learning centers were reduced
界面控件Telerik UI for WPF - 如何使用RadSpreadsheet记录或评论
04 pyechars 地理图表(示例代码+效果图)
Deployment之滚动更新策略。
leetcode 376. Wiggle Subsequence
LeetCode 移除元素&移动零
LeetCode206 反转链表
单调栈Monotonic Stack
Review the IO stream again, and have an in-depth understanding of serialization and deserialization
Leetcode94. Middle order traversal of binary trees
SuperMap game engine license module division
scala 转换、过滤、分组、排序