当前位置:网站首页>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。
到此,分析结束!
边栏推荐
- 新能源销冠宏光MINIEV,有着怎样的产品力?
- Learn NLP with Transformer (Chapter 8)
- 为什么重写equals()方法必须要重写hashCode()方法
- Compressed list ziplist of redis
- C# Newtonsoft.Json 高级用法
- Reptile foundation I
- Mlx90640 infrared thermal imager temperature measurement module development notes (V)
- MySQL | GROUP_ The concat function concatenates the values of a column with commas
- Review recitation finishing version
- Game backpack system, "inventory Pro plug-in", research and learning ----- mom doesn't have to worry that I won't make a backpack anymore (unity3d)
猜你喜欢

圆角大杀器,使用滤镜构建圆角及波浪效果!

Mlx90640 infrared thermal imager temperature measurement module development notes (V)

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

Nowcodertop12-16 - continuous updating

只知道预制体是用来生成物体的?看我如何使用Unity生成UI预制体

Esp8266 uses drv8833 drive board to drive N20 motor

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

PostgreSQL stepping on the pit | error: operator does not exist: UUID = character varying

工作面试总遇秒杀?看了京东T8大咖私藏的秒杀系统笔记,已献出膝盖

Fillet big killer, use filter to build fillet and wave effect!
随机推荐
从宏观到微观 零基础 详解bert
[IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training
【IJCAI 2022】参数高效的大模型稀疏训练方法,大幅减少稀疏训练所需资源
Learn NLP with Transformer (Chapter 3)
Common web attacks and defense
Implementation of recommendation system collaborative filtering in spark
新能源销冠宏光MINIEV,有着怎样的产品力?
Txt to CSV file, blank lines appear every other line
Mlx90640 infrared thermal imager temperature measurement module development notes (V)
How can you use unity without several plug-ins? Unity various plug-ins and tutorial recommendations
LVS负载均衡之LVS-DR搭建Web群集与LVS结合Keepalived搭建高可用Web群集
Leetcode sword finger offer 27. image of binary tree
Learn NLP with Transformer (Chapter 6)
Code representation learning: introduction to codebert and other related models
Several common PCB surface treatment technologies!
The B2B2C multi merchant system has rich functions and is very easy to open!!!
Learn NLP with Transformer (Chapter 2)
Leetcode sword finger offer 28. symmetric binary tree
What kind of product power does Hongguang miniev, the top seller of new energy, have?
[树] 100. 相同的树