当前位置:网站首页>Filter过滤器解决request请求参数乱码的原理解析
Filter过滤器解决request请求参数乱码的原理解析
2022-07-25 10:35:00 【努力的clz】
本篇文章是对SpringMVC出现request请求参数乱码情况解决办法博客中“解决措施1”的原理解析,个人认为了解一些简单技术背后的原理对个人编程还是挺有帮助的。
如果有request请求参数乱码问题的小伙伴可以去查看下我上面提到的那片博客,希望对大家有所帮助!
1、进入CharacterEncodingFilter.class

2、CharacterEncodingFilter继承结构图
可以看出CharacterEncodingFilter的曾祖父居然是Filter


3、doFilter( )方法
我们重点看Filter接口的doFilter( )方法的实现情况:
doFilter( )方法在OncePerRequestFilter里实现:
关键:doFilter( )方法里执行了doFilterInternal( ),而doFilterInternal( )方法的实现又在OncePerRequestFilter的子类CharacterEncodingFilter里实现。
绕了一圈又回到了CharacterEncodingFilter类了,看下关键代码:
4、回顾下web.xml里的配置信息

5、CharacterEncodingFilter类中的属性
查看源代码,CharacterEncodingFilter类有三个属性,并且发现无论有参还是无参构造方法forceRequestEncoding、
forceResponseEncoding这两个属性的初始值都是false。下面的主要目的就是解释为什么要改成ture?
6、关键代码

1、我们在web.xml里设置了encoding为UTF-8,所以该值不为空。
2、我们在web.xml里设置了forceRequestEncoding、forceResponseEncoding两个Boolean值为true,所以if语句可以执
行。
3、分别将request、response的编码设置成encoding,也就是UTF-8。
到此,分析结束!
边栏推荐
- Multiply Floyd "suggestions collection"
- 玩游戏想记录一下自己超神的瞬间?那么就来看一下如何使用Unity截图吧
- 从宏观到微观 零基础 详解bert
- Nowcodertop7-11 - continuous updating
- 工作面试总遇秒杀?看了京东T8大咖私藏的秒杀系统笔记,已献出膝盖
- Detailed explanation of the implementation method of DNS separation and resolution
- HCIP(13)
- B2B2C多商户系统功能丰富,极易二开!!!
- HCIA experiment (08)
- PostgreSQL踩坑 | ERROR: operator does not exist: uuid = character varying
猜你喜欢

How to judge the performance of static code quality analysis tools? These five factors must be considered

HCIA experiment (07) comprehensive experiment
![[flask advanced] deeply understand the application context and request context of flask from the source code](/img/67/88c21967da28d09694568ebdaae44c.png)
[flask advanced] deeply understand the application context and request context of flask from the source code

活动报名 | 玩转 Kubernetes 容器服务提高班正式开营!

What kind of product power does Hongguang miniev, the top seller of new energy, have?

Common web attacks and defense

SQL language (III)

BGP federal experiment

用Unity不会几个插件怎么能行?Unity各类插件及教程推荐

NowCoderTOP1-6——持续更新ing
随机推荐
ArcMap无法启动解决方法
Web mobile terminal: touchmove realizes local scrolling
web移动端:touchmove实现局部滚动
PostgreSQL stepping on the pit | error: operator does not exist: UUID = character varying
小区蔬菜配送的小程序
Hcip experiment (04)
新能源销冠宏光MINIEV,有着怎样的产品力?
Understanding: idea uses Scala to write wordcount programs and generate jar packages
LVS负载均衡之LVS-NAT与LVS-DR模式原理详解
Detailed explanation of zero basis from macro to micro Bert
HCIA experiment (09)
Let sports happen naturally, and fire creates a new lifestyle
将字符串转换为数字
Hcip experiment (03)
Learn NLP with Transformer (Chapter 4)
爬虫基础一
C# Newtonsoft. Jason advanced usage
Syncronized lock upgrade process
信息熵的定义
Redis 入门