当前位置:网站首页>记录--关于JSP前台传参数到后台出现乱码的问题
记录--关于JSP前台传参数到后台出现乱码的问题
2022-06-24 06:33:00 【炮炮炮~~】
记录–关于JSP前台传参数到后台出现乱码的问题
记录一下学习JSP时遇到的问题和解决办法
方法一
出现乱码首先查看代码页面的编码设置,项目里所有页面的编码需要统一
可以统一成UTF-8,或者GB2312等
方法二
在需要传字符的代码前加上:
request.setCharacterEncoding("UTF-8");
这个里面以UTF-8为例,需要其他编码的自行修改
这里时调用request(request是jsp的内置对象,主要用来处理客户端浏览器提交的请求中的各项参数和选项)的setCharacterEncoding方法
方法三
编写一个java工具类,写一个处理乱码的方法,需要时调用
public static String toChinese(String str){
//进行转码操作的方法
if(str==null)
str="";
try {
str=new String(str.getBytes("ISO-8859-1"),"gb2312");
} catch (UnsupportedEncodingException e) {
str="";
e.printStackTrace();
}
return str;
}
工具类里其实不止可以写转码的方法,还可以写数据类型转换的方法等
方法四
如果上诉方法尝试后问题没得到解决,那请尝试最后一种方法
这里我以我自己的例子来说明一下
图中我已经使用了之前的一些方法,可以没有解决我的乱码问题,在服务器上运行还是出现问号(??)
要怎么解决呢?
下面来说一下怎么做:
找到tomcat安装的路径,比如我的:D:\ruanjian\apache-tomcat-9.0.8,在路径下找到conf这个文件夹,打开
找到server.xml
打开,找到里面的connector标签那一行:

在标签属性里加上:URIEncoding=“UTF-8”
保存,关闭,我们检查一下是否成功
为了测试传的字符,我用控制台输出一下,这样方便查看
控制台上已经输出了正确的中文字,搞定!
之后还有方法再补充,欢迎各位指正!!!(鞠躬)
以上!
边栏推荐
- Another authoritative recommendation! Tencent zero trust was recognized by omdia Report
- Correct way to update Fedora image Yum source to Tencent cloud Yum source
- When easynvs is deployed on the project site, easynvr cannot view the corresponding channel. Troubleshooting
- Authoritative recognition! Tencent cloud data security Zhongtai was selected as the 2021 pioneer practice case
- ServiceStack. Source code analysis of redis (connection and connection pool)
- The gadgets developed by freshmen are popular. Netizen: my food is good
- What are the categories of edge computing devices
- WordPress applet build applet from zero to one [server configuration]
- Talk about how to dynamically specify feign call service name according to the environment
- Easynvr is optimized when a large number of videos are not online or unstable due to streaming failure
猜你喜欢

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

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

puzzle(019.1)Hook、Gear

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

Enter the software test pit!!! Software testing tools commonly used by software testers software recommendations
![[fault announcement] one stored procedure brings down the entire database](/img/7c/e5adda73a077fe4b8f04b59d1e0e1e.jpg)
[fault announcement] one stored procedure brings down the entire database

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

【二叉树】——二叉树中序遍历
随机推荐
When the VPC main network card has multiple intranet IP addresses, the server cannot access the network internally, but the server can be accessed externally. How to solve this problem
Linux Apache setting compression and caching
How to choose CMS website system for website construction
Raspberry PI (bullseye) replacement method of Alibaba cloud source
Excellent tech sharing | research and application of Tencent excellent map in weak surveillance target location
Replacing human eyes -- visual inspection technology
How to quickly master the orders message in sportisimo EDI project?
Coding platform project construction guide
"Adobe international certification" in the design industry, why can't big but big designs have good results?
Come on, it's not easy for big factories to do projects!
TRTC applet custom message
Why computers often crash
How to apply 5g smart pole to smart highway
Use of SAP QM inspection points
Koa source code analysis
The 2021 Tencent digital ecology conference landed in Wuhan, waiting for you to come to the special session of wechat with low code
The difference between ArrayList and LinkedList and the principle of using scene locality
Spirit information development log (3)
Easyscreen live streaming component pushes RTSP streams to easydss for operation process sharing
[fault announcement] one stored procedure brings down the entire database