当前位置:网站首页>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));}边栏推荐
- OPNsense安装配置Zenarmor
- Centos7环境使用Mysql离线安装包安装Mysql5.7
- 暑期总结4
- LeetCode 445. Adding Two Numbers II
- Analysis of the name matching process between the LCD driver and the device (Tiny4412)
- 传三星3nm斩获第二家客户,目前产能已供不应求
- dedecms支持Word内容一键导入
- 面试官:项目中 Dao、Service、Controller、Util、Model 怎么划分的?
- VSCode remote connection server error: Could not establish connection to "xxxxxx" possible error reasons and solutions
- 力扣练习——60 二叉搜索子树的最大键值和
猜你喜欢
随机推荐
A case of violent parameter tuning in machine learning
搜索--01
Licking Exercise - 59 From Binary Search Trees to Greater Sum Trees
不止跑路,拯救误操作rm -rf /*的小伙儿
LeetCode50天刷题计划(Day 18—— 搜索旋转排序数组(8.50-12.00)
jlink and swd interface definition
HDU 4135: Co-prime (the principle of inclusion and exclusion)
微信小程序提交审核历史版本记录从哪里查看
一文读懂NFT数字藏品为何风靡全球?
LeetCode 19. Delete the Nth last node of the linked list
模块九 - 设计电商秒杀系统
单目操作符(含原码反码补码转换)
three.js模糊玻璃效果
态路小课堂丨如何为CXP光模块选择光纤跳线?
LeetCode 92. 反转链表 II
2016,还是到了最后
Go 事,Gopher 要学的数字类型,变量,常量,运算符 ,第2篇
VSCode远程连接服务器报错:Could not establish connection to “xxxxxx”的可能错误原因及解决
Buckle Exercise - 61 Sort by frequency of characters
LeetCode 24. Swap nodes in linked list pairwise









