当前位置:网站首页>记录--关于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”
保存,关闭,我们检查一下是否成功
为了测试传的字符,我用控制台输出一下,这样方便查看
控制台上已经输出了正确的中文字,搞定!
之后还有方法再补充,欢迎各位指正!!!(鞠躬)
以上!
边栏推荐
- 35岁危机?内卷成程序员代名词了
- puzzle(019.1)Hook、Gear
- Differences between JSON objects and JSON strings
- Discussion on NFT Technology
- Member management system PC side building tutorial (I)
- 目标5000万日活,Pwnk欲打造下一代年轻人的“迪士尼乐园”
- Wordpress5.8 is coming, and the updated website is faster!
- Just now, we received a letter of thanks from Bohai University.
- How long will it take for us to have praise for Shopify's market value of 100 billion yuan?
- How fast? Good province!
猜你喜欢
![跳跃游戏II[贪心练习]](/img/e4/f59bb1f5137495ea357462100e2b38.png)
跳跃游戏II[贪心练习]

云上本地化运营,东非第一大电商平台Kilimall的出海经

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

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

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

【二叉树】——二叉树中序遍历
Oracle case: ohasd crash on AIX

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

ServiceStack. Source code analysis of redis (connection and connection pool)

Enter the software test pit!!! Software testing tools commonly used by software testers software recommendations
随机推荐
Quick reference table of PHP security configuration maintained by OWASP
How does go limit the flow of services?
云上本地化运营,东非第一大电商平台Kilimall的出海经
Interpreting the new features of Appstore: Customizing product pages and a/b test tools
The product layout is strengthened, the transformation of digital intelligence is accelerated, and FAW Toyota has hit 2022million annual sales
What transmission modes does the IOT data gateway support
Another authoritative recommendation! Tencent zero trust was recognized by omdia Report
Little transparent apprentice's way to go ashore
Correct way to update Fedora image Yum source to Tencent cloud Yum source
Why the computer can't start
Apache enables gzip compressed web page transmission method
[5 minutes to play lighthouse] take you to the light kubernetes release k3s
Multi objective Optimization Practice Based on esmm model -- shopping mall
Just now, we received a letter of thanks from Bohai University.
Talk about how to dynamically specify feign call service name according to the environment
Forbid viewing source code in web page (protect source code)
Coding and codesign: make design and development easier
35岁危机?内卷成程序员代名词了
Urban Waterlogging Monitoring and early warning system
Excellent tech sharing | research and application of Tencent excellent map in weak surveillance target location