当前位置:网站首页>Record -- about the problem of garbled code when JSP foreground passes parameters to the background
Record -- about the problem of garbled code when JSP foreground passes parameters to the background
2022-06-24 06:39:00 【Cannon cannon~~】
Record – About JSP There is a garbled code problem when the foreground transmits parameters to the background
Record your study JSP The problems and solutions in the process of construction
Method 1
In case of garbled code, first check the code settings on the code page , The coding of all pages in the project needs to be unified 
Can be unified into UTF-8, perhaps GB2312 etc.
Method 2
Add... Before the code that needs to pass characters :
request.setCharacterEncoding("UTF-8");
The inside of this is UTF-8 For example , You need to modify other codes by yourself
Called here request(request yes jsp Built in objects for , It is mainly used to process various parameters and options in the request submitted by the client browser ) Of setCharacterEncoding Method
Method 3
Write a java Tool class , Write a method to deal with garbled code , Call... When needed
public static String toChinese(String str){
// The method of transcoding
if(str==null)
str="";
try {
str=new String(str.getBytes("ISO-8859-1"),"gb2312");
} catch (UnsupportedEncodingException e) {
str="";
e.printStackTrace();
}
return str;
}
In fact, the tool class can not only write transcoding methods , You can also write data type conversion methods
Method four
If the appeal method is tried and the problem is not solved , Please try the last method
Here I use my own example to illustrate 
I have used some of the previous methods in the figure , Can not solve my garbled code problem , There is still a question mark when running on the server (??)
How to solve it ?
Let's talk about how to do it :
find tomcat Installation path , Such as my :D:\ruanjian\apache-tomcat-9.0.8, Find... Under the path conf This folder , open 
find server.xml
open , Find the inside connector Label line :

Add... To the tag attribute :URIEncoding=“UTF-8”
preservation , close , Let's check if it works 
To test the transmitted characters , I use the console to output , It's easy to see 
The correct Chinese characters have been output on the console , Get it done !
Then there are ways to add , Welcome to correct !!!( Bow )
above !
边栏推荐
- Why computers often crash
- puzzle(019.1)Hook、Gear
- How to choose CMS website system for website construction
- [5 minutes to play lighthouse] take you to the light kubernetes release k3s
- Printer connection mode
- Station B collapsed. Let's talk to the injured programmers
- Rhel8 series update image Yum source is Tencent cloud Yum source
- WordPress pill applet build applet from zero to one [install and configure WordPress site]
- 项目Demo
- Easyscreen live streaming component pushes RTSP streams to easydss for operation process sharing
猜你喜欢

缓存操作rockscache原理图

About Stacked Generalization
![Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.](/img/2c/d04f5dfbacb62de9cf673359791aa9.png)
Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.

【二叉数学习】—— 树的介绍

目标5000万日活,Pwnk欲打造下一代年轻人的“迪士尼乐园”

程序员使用个性壁纸

云上本地化运营,东非第一大电商平台Kilimall的出海经

基于三维GIS系统的智慧水库管理应用

【JUC系列】Executor框架之CompletionFuture
Fault analysis | using --force to batch import data leads to partial data loss
随机推荐
Small programs import Excel data in batches, and cloud development database exports CVS garbled code solution
Actual combat | how to deploy flask project using wechat cloud hosting
Tencent cloud VPC machine, no image when installing monitoring components
SAP hum unbinds Hu from delivery order
Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.
In the half year, there were 2.14 million paying users, a year-on-year increase of 62.5%, and New Oriental online launched its private domain
Raspberry PI (bullseye) replacement method of Alibaba cloud source
Produce kubeconfig with permission control
Nine possibilities of high CPU utilization
Surveying and mapping principle of GIS coordinate system: geoid / datum / reference ellipsoid /epsg/sri/wkt
云上本地化运营,东非第一大电商平台Kilimall的出海经
leetcode:85. 最大矩形
Do you want to research programming? I got six!
text classification with RNN
Word cannot copy and paste processing method
The 2021 Tencent digital ecology conference landed in Wuhan, waiting for you to come to the special session of wechat with low code
"Adobe international certification" in the design industry, why can't big but big designs have good results?
"Adobe international certification" design white must understand the color theory, absolutely full of dry goods
The three-year action plan of the Ministry of industry and information technology has been announced, and the security industry has ushered in major development opportunities!
Provide SFTP connection for Amazon S3