当前位置:网站首页>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));}边栏推荐
- 网络基础(第一节)
- SMIC CIM localization project suspended?Rising software: not shut down, changed to remote development!
- 模块九 - 设计电商秒杀系统
- 单目操作符(含原码反码补码转换)
- StoneDB Document Bug Hunting Season 1
- ViT结构详解(附pytorch代码)
- 做自媒体月入几万?博主们都在用的几个自媒体工具
- LeetCode 109. Sorted Linked List Conversion Binary Search Tree
- codevs 2370 小机房的树 (LCA)
- Excel函数公式大全—HLOOKUP函数
猜你喜欢

rider内Mono脚本找不到引用资源

实现内网穿透的最佳解决方案(无实名认证,完全免费)

快手“弃”有赞与微盟“结亲”,电商SaaS行业竞争格局将变?

再有人问你分布式事务,把这篇扔给他

How many constants and data types do you remember?

Analysis of the implementation principle of UUID from the perspective of source code

ViT结构详解(附pytorch代码)

使用哈工大LTP测试分词并且增加自定义字典

模块九 - 设计电商秒杀系统

英特尔推送20220809 CPU微码更新 修补Intel-SA-00657安全漏洞
随机推荐
It is rumored that Samsung 3nm has won the second customer, and the current production capacity is in short supply
LeetCode 92. 反转链表 II
基于UiAutomator2+PageObject模式开展APP自动化测试实战
一文读懂NFT数字藏品为何风靡全球?
LeetCode 445. Adding Two Numbers II
石墨文档打开文档时快速定位到上次写的位置
常量及数据类型你还记得多少?
Not just running away, but saving the guy who mishandled rm -rf /*
搜索--01
Interviewer: How are Dao, Service, Controller, Util, and Model divided in the project?
LeetCode 19. 删除链表的倒数第 N 个结点
Excel函数公式大全—LOOKUP函数
有哪些好用的性能测试工具推荐?性能测试报告收费标准
Excel函数公式大全—HLOOKUP函数
Licking Exercise - 58 Verifying Binary Search Trees
中芯CIM国产化项目暂停?上扬软件:未停摆,改为远程开发!
机器学习之暴力调参案例
std::move()
If someone asks you about distributed transactions again, throw this to him
网络基础(第一节)