当前位置:网站首页>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 !
边栏推荐
- When easynvs is deployed on the project site, easynvr cannot view the corresponding channel. Troubleshooting
- Web address domain name IP query method, what is the use of domain name
- go 断点续传
- On BOM and DOM (2): DOM node hierarchy / attributes / Selectors / node relationships / detailed operation
- Let's talk about BOM and DOM (5): dom of all large Rovers and the pits in BOM compatibility
- WordPress pill applet build applet from zero to one [install and configure WordPress site]
- 学生管理系统页面跳转及数据库连接
- The installation method of apache+mysql+php running environment under Windows
- Record of waic 2021 round table conference 𞓜 cross border dialogue: current situation and future of AI and sustainable development
- Enter the software test pit!!! Software testing tools commonly used by software testers software recommendations
猜你喜欢

puzzle(019.1)Hook、Gear

缓存操作rockscache原理图

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

【JUC系列】Executor框架之CompletionFuture

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

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

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

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

The product layout is strengthened, the transformation of digital intelligence is accelerated, and FAW Toyota has hit 2022million annual sales

Manual for automatic testing and learning of anti stepping pits, one for each tester
随机推荐
Easyrtc call error `failed to execute'send'on'rtcdatachannel'
Authoritative recognition! Tencent cloud data security Zhongtai was selected as the 2021 pioneer practice case
Why computers often crash
If you want to learn programming well, don't recite the code!
What is a secondary domain name primary domain name how to apply for a secondary domain name
Fault analysis | using --force to batch import data leads to partial data loss
Easyscreen live streaming component pushes RTSP streams to easydss for operation process sharing
From home to Ali, a year for junior students to apply for jobs
Go excel export tool encapsulation
Distributed cache breakdown
Tencent Security jointly established a data security committee
Quick reference table of PHP security configuration maintained by OWASP
Operation and maintenance dry goods | how to improve the business stability and continuity through fault recovery?
puzzle(019.1)Hook、Gear
When should I use Apache Druid
Urban Waterlogging Monitoring and early warning system
The product layout is strengthened, the transformation of digital intelligence is accelerated, and FAW Toyota has hit 2022million annual sales
Spirit information development log (1)
The 2021 Tencent digital ecology conference landed in Wuhan, waiting for you to come to the special session of wechat with low code
[5 minutes to play lighthouse] take you to the light kubernetes release k3s