当前位置:网站首页>Servlet---Solve the problem of Chinese garbled characters in post requests
Servlet---Solve the problem of Chinese garbled characters in post requests
2022-08-10 12:06:00 【i love brown bears】
@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {// Solve the problem of Chinese garbled charactersreq.setCharacterEncoding("UTF-8");// get request parametersString username = req.getParameter("username");String password = req.getParameter("password");String hobby = req.getParameter("hobby");// use this method if there are multiple valuesString[] hobby2 = req.getParameterValues("hobby");System.out.println("username=>"+username);System.out.println("password=>"+password);System.out.println("hobby=>"+hobby);System.out.println("hobby=>"+ Arrays.toString(hobby2));}
Title
When our request is a post request, if there is Chinese in the form, there will be a problem of Chinese garbled characters
Of course, the solution to this problem is very simple, that is, modify the character encoding set
req.setCharacterEncoding("UTF-8");
Attention!!!!!!
req.setCharacterEncoding("UTF-8"); This statement must be used before getting the requested parameters to achieve the effectspan>
Like the code below, there will still be garbled characters!!!!
@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {String username = req.getParameter("username");// Solve the problem of Chinese garbled charactersreq.setCharacterEncoding("UTF-8");// get request parametersString password = req.getParameter("password");// use this method if there are multiple valuesString[] hobby = req.getParameterValues("hobby");System.out.println("username=>"+username);System.out.println("password=>"+password);System.out.println("hobby=>"+ Arrays.toString(hobby));}
边栏推荐
- LeetCode 19. 删除链表的倒数第 N 个结点
- 一文详解 implementation api embed
- Pulling drills - 56 Finding the right interval
- Licking Exercise - 58 Verifying Binary Search Trees
- Centos7 environment uses Mysql offline installation package to install Mysql5.7
- Does your child lack self-discipline?Ape Counseling: Pay attention to "blank" in the schedule to give children more control
- 基于UiAutomator2+PageObject模式开展APP自动化测试实战
- 一文读懂NFT数字藏品为何风靡全球?
- Configuration swagger
- LeetCode50天刷题计划(Day 17—— 下一个序列(14.50-16.30)
猜你喜欢
石墨文档打开文档时快速定位到上次写的位置
基于UiAutomator2+PageObject模式开展APP自动化测试实战
Where can I view the version record of WeChat applet submission review history?
If someone asks you about distributed transactions again, throw this to him
Network sockets (UDP and TCP programming)
使用哈工大LTP测试分词并且增加自定义字典
机器学习之暴力调参案例
皕杰报表在传参乱码
StoneDB 文档捉虫活动第一季
一文读懂NFT数字藏品为何风靡全球?
随机推荐
搜索--01
LeetCode 369. Plus One Linked List(链表加1)
7、Instant-ngp
LeetCode50天刷题计划(Day 18—— 搜索旋转排序数组(8.50-12.00)
开源的作者,也有个生活问题
codevs 2370 Small room tree (LCA)
LeetCode 445. Adding Two Numbers II
LeetCode50天刷题计划(Day 19—— 在排序数组中查找元素的第一个和最后一个位置(9.10-10.40)
机器学习之暴力调参案例
模块九 - 设计电商秒杀系统
Introduction to Software Architecture
一文读懂NFT数字藏品为何风靡全球?
Where can I view the version record of WeChat applet submission review history?
LeetCode 19. 删除链表的倒数第 N 个结点
快手“弃”有赞与微盟“结亲”,电商SaaS行业竞争格局将变?
ssm框架搭建过程[通俗易懂]
英特尔推送20220809 CPU微码更新 修补Intel-SA-00657安全漏洞
HDU 4372:Count the Buildings (Stirling数)
制品库是什么?
传三星3nm斩获第二家客户,目前产能已供不应求