当前位置:网站首页>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 !
边栏推荐
- 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
- How to give full play to the advantages of Internet of things by edge computing intelligent gateway
- Kubernets traifik proxy WS WSS application
- Vscode1.58 version update record Previous + related article summary
- ServiceStack. Source code analysis of redis (connection and connection pool)
- Come on, it's not easy for big factories to do projects!
- Go excel export tool encapsulation
- 项目Demo
- How to build a website with a domain name? Is the domain name very cheap
- When should I use Apache Druid
猜你喜欢

云上本地化运营,东非第一大电商平台Kilimall的出海经
Fault analysis | using --force to batch import data leads to partial data loss

Manual for automatic testing and learning of anti stepping pits, one for each tester

【JUC系列】Executor框架之CompletionFuture

leetcode:1856. 子数组最小乘积的最大值

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

C语言学生管理系统——可检查用户输入合法性,双向带头循环链表

35岁危机?内卷成程序员代名词了

A cigarette of time to talk with you about how novices transform from functional testing to advanced automated testing

缓存操作rockscache原理图
随机推荐
Royal treasure: an analysis of SQL algebra optimization
What is Druid
Introduction to QWidget attribute table in QT Designer
typescript vscode /bin/sh: ts-node: command not found
Just now, we received a letter of thanks from Bohai University.
SAP hum unbinds Hu from delivery order
Koa source code analysis
Let's talk about BOM and DOM (5): dom of all large Rovers and the pits in BOM compatibility
记录--关于virtual studio2017添加报表控件的方法--Reportview控件
Why computers often crash
The installation method of apache+mysql+php running environment under Windows
Source code analysis of current limiting component uber/ratelimit
云上本地化运营,东非第一大电商平台Kilimall的出海经
创客教育给教师发展带来的挑战
How accurate are the two common methods of domain name IP query
DHCP server setup
Small programs import Excel data in batches, and cloud development database exports CVS garbled code solution
Authoritative recognition! Tencent cloud data security Zhongtai was selected as the 2021 pioneer practice case
Code scanning | a sharp tool for controlling code quality
Free and easy-to-use screen recording and video cutting tool sharing