当前位置:网站首页>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 .
边栏推荐
- STM32F103 several special pins are used as ordinary io. Precautions and data loss of backup register 1,2
- Leetcode 1518. wine change
- Use json.stringify() to format data
- C语言项目中使用json
- Insufficient permission to pull server code through Jenkins and other precautions
- Leetcode remove element & move zero
- [base] what is the optimization of optimization performance?
- Sliding Window
- LeetCode206 反转链表
- MSP430 开发中遇到的坑(待续)
猜你喜欢

试用copilot过程中问题解决

苏黎世联邦理工学院 | 具有可变形注意Transformer 的基于参考的图像超分辨率(ECCV2022))

机器学习实战-集成学习-23

Unity installs the device simulator

03 pyechars 直角坐标系图表(示例代码+效果图)

HC-05蓝牙模块调试从模式和主模式经历

Quick read in

揭秘界面控件DevExpress WinForms为何弃用受关注的MaskBox属性

Aopmai biological has passed the registration: the half year revenue is 147million, and Guoshou Chengda and Dachen are shareholders

Jinshanyun rushes to the dual main listing of Hong Kong stocks: the annual revenue of 9billion is a project supported by Lei Jun
随机推荐
Machine learning practice - integrated learning-23
Fundamentals of machine learning - principal component analysis pca-16
Deployment之滚动更新策略。
[cute new problem solving] climb stairs
What SaaS architecture design does a software architect need to know?
MSP430 开发中遇到的坑(待续)
05 pyechars 基本图表(示例代码+效果图)
LeetCode 移除元素&移动零
Siemens docking Leuze BPS_ 304i notes
leetcode:704二分查找
LeetCode 42.接雨水
机器学习实战-逻辑回归-19
西门子对接Leuze BPS_304i 笔记
Linear classifier (ccf20200901)
界面控件Telerik UI for WPF - 如何使用RadSpreadsheet记录或评论
Ten prohibitions for men and women in love
05 pyechars basic chart (example code + effect diagram)
Science heavyweight: AI design protein has made another breakthrough, and it can design specific functional proteins
VS code更新后不在原来位置
LeetCode84 柱状图中最大的矩形