当前位置:网站首页>记录--关于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”
保存,关闭,我们检查一下是否成功
为了测试传的字符,我用控制台输出一下,这样方便查看
控制台上已经输出了正确的中文字,搞定!
之后还有方法再补充,欢迎各位指正!!!(鞠躬)
以上!
边栏推荐
- Apache enables gzip compressed web page transmission method
- How to batch move topics to different categories in discover
- How accurate are the two common methods of domain name IP query
- Flutter environment installation & operation
- Talk about how to dynamically specify feign call service name according to the environment
- Skips allowed on SAP QM material master inspection type
- Analysis on the influence of "network security policy issued successively" on Enterprises
- Oracle case: ohasd crash on AIX
- Web automation test (3): Selenium basic course of web function automation test
- text classification with RNN
猜你喜欢

【JUC系列】Executor框架之CompletionFuture

A cigarette of time to talk with you about how novices transform from functional testing to advanced automated testing
![[fault announcement] one stored procedure brings down the entire database](/img/7c/e5adda73a077fe4b8f04b59d1e0e1e.jpg)
[fault announcement] one stored procedure brings down the entire database

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

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

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

puzzle(019.1)Hook、Gear

基于三维GIS系统的智慧水库管理应用
![跳跃游戏II[贪心练习]](/img/e4/f59bb1f5137495ea357462100e2b38.png)
跳跃游戏II[贪心练习]
![Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.](/img/2c/d04f5dfbacb62de9cf673359791aa9.png)
Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.
随机推荐
Configure PHP development environment in MAC environment: apache+php+mysql
How to give full play to the advantages of Internet of things by edge computing intelligent gateway
Member management system PC side building tutorial (I)
typescript vscode /bin/sh: ts-node: command not found
EEG microstate as a continuous phenomenon
Tencent security release data security compliance capability map
Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.
Operation and maintenance dry goods | how to improve the business stability and continuity through fault recovery?
How to choose CMS website system for website construction
The product layout is strengthened, the transformation of digital intelligence is accelerated, and FAW Toyota has hit 2022million annual sales
WordPress pill applet build applet from zero to one [wordpress pagoda configure SSL pseudo static]
From home to Ali, a year for junior students to apply for jobs
The gadgets developed by freshmen are popular. Netizen: my food is good
Koa source code analysis
MySQL forgets root password cracking root password cracking all user passwords, shell script
In Tencent, my trial period summary
35岁危机?内卷成程序员代名词了
Small programs import Excel data in batches, and cloud development database exports CVS garbled code solution
Deploy DNS server using dnsmasq
Record of waic 2021 round table conference 𞓜 cross border dialogue: current situation and future of AI and sustainable development