当前位置:网站首页>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 !
边栏推荐
- TRTC applet custom message
- 跳跃游戏II[贪心练习]
- 创客教育给教师发展带来的挑战
- Operation and maintenance dry goods | how to improve the business stability and continuity through fault recovery?
- Interpreting the new features of Appstore: Customizing product pages and a/b test tools
- WordPress pill applet build applet from zero to one [pagoda panel installation configuration]
- How to open a hidden file
- What is Druid
- Urban Waterlogging Monitoring and early warning system
- Easyrtc call error `failed to execute'send'on'rtcdatachannel'
猜你喜欢

【JUC系列】Executor框架之CompletionFuture

解读AI机器人产业发展的顶层设计

创客教育给教师发展带来的挑战

缓存操作rockscache原理图

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

Enter the software test pit!!! Software testing tools commonly used by software testers software recommendations

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

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

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

leetcode:85. 最大矩形
随机推荐
Excellent tech sharing | research and application of Tencent excellent map in weak surveillance target location
About Stacked Generalization
Fault analysis | using --force to batch import data leads to partial data loss
go 断点续传
What is Druid
Come on, it's not easy for big factories to do projects!
Koa source code analysis
Record of waic 2021 round table conference 𞓜 cross border dialogue: current situation and future of AI and sustainable development
C语言学生管理系统——可检查用户输入合法性,双向带头循环链表
leetcode:剑指 Offer 26:判断t1中是否含有t2的全部拓扑结构
What are the categories of edge computing devices
Five minute run through 3D map demo
DHCP server setup
Innovating the security service mode, deeply convinced that the organization has been equipped with a "continuous online expert group"
云上本地化运营,东非第一大电商平台Kilimall的出海经
On BOM and DOM (2): DOM node hierarchy / attributes / Selectors / node relationships / detailed operation
Vscode1.58 version update record Previous + related article summary
In Tencent, my trial period summary
Just now, we received a letter of thanks from Bohai University.
On BOM and DOM (3): DOM node operation - element style modification and DOM content addition, deletion, modification and query